Using Polymer conditional attributes with HAML - haml

According to the documentation for Polymer expressions, you can bind data to conditionally assign an attribute using the conditional attribute syntax:
Conditional attributes
For boolean attributes, you can control whether or not the attribute
appears using the special conditional attribute syntax:
attribute?={{boolean-expression}}
That's great, but I'm using HAML where attributes are assigned to elements like this:
%element{attribute: "value"}
I can't add a question mark before that colon without HAML giving me a syntax error.
So how can I use Polymer's conditional attributes (or a functional equivalent) when I'm using HAML to generate my HTML?

One potential solution is to use the :plain filter to insert raw HTML into your HAML file:
:plain
<element attribute?={{boolean-expression}}></element>
A bit ugly, but it seems to work.
If you need to enclose some HAML-generated tags in one of these plain HTML tags, you'll need to use the :plain filter twice; once for the opening tag, and once for the closing tag.
:plain
<element attribute?={{boolean-expression}}>
-# HAML Content Here
:plain
</element>
Be sure not to indent your HAML code after the opening tag, otherwise it will become part of the "raw HTML" output and get sent as plain text to the browser instead of being processed as HAML.

The current version of HAML (4.0.6) supports conditional attributes:
%core-menu{hidden?: '{{!globals.current_series_detail}}'}
Make sure you're not putting a space before the question mark.

Related

Allow custom attribute to a script tag element?

I can't validate script tag with attribute nomodule.
I am using odoo framework which is a python backend. It is using lxml to validate xml views or pages. I am building a view with a script tag like:
<script src="src.js" nomodule></script>
It returns an error
lxml.etree.XMLSyntaxError: Specification mandate value for attribute nomodule
However this should be valid according to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
Is there a way so that I can make the parser ignore this new attribute or I can bypass such as special data or character.
That's possibly because XML != HTML. And as you can see in the error, it's an XML error.
Is an xml attribute without a value, valid? --> your attribute isn't valid.
You need to specify the attribute value always in xml. Odoo uses xml to produce html, so you need to comply with xml rules. You can do it in this case by specifying an empty value for xml attribute like this:
<script src="src.js" nomodule=””></script>

Sitecore 7 Lucene: strip HTML from computed field

I am pasting together all "paragraph" child nodes from an "article" node in a computed field. This is to achieve that an article can be searched & found by its paragraph contents.
To achieve this, I did the following, under the <fields hint="raw:AddComputedIndexField"> node:
<field fieldName="Paragraphs" storageType="YES" indexType="TOKENIZED">
MyWebsite.ComputedFields.Paragraphs,MyWebsite
</field>
In this computed field, I concat the paragraph HTML bodies together.
I was assuming Sitecore would strip the HTML for me (like it does for rich text fields), but it does noet.
For "rich text" fields, it is probably the RichTextFieldReader that strips the HTML tags out. Decompiling the code confirms this.
The RichTextFieldReader is configured in the FieldReaders section. Trying to add a raw:AddFieldReaderByFieldNamesection below, does not seem to do anything.
The full section looks as follows, but does not work in this setup:
<FieldReaders type="Sitecore.ContentSearch.FieldReaders.FieldReaderMap, Sitecore.ContentSearch">
<mapFieldByTypeName hint="raw:AddFieldReaderByFieldTypeName">
....default stuff here...
</mapFieldByTypeName>
<mapFieldByFieldName hint="raw:AddFieldReaderByFieldName">
<fieldReader fieldName="Paragraphs" fieldReaderType="Sitecore.ContentSearch.FieldReaders.RichTextFieldReader, Sitecore.ContentSearch"></fieldReader>
</mapFieldByFieldName>
</FieldReaders>
Any other clues on how to achieve this (by config, not by using HTML agility pack etc)
The problem is the mapFieldByFieldName is expecting to match a field with that name from the Sitecore item, not a custom computed field in your index so the field reader is never called.
I don't know how to achieve this from config, but if you do not want to directly use HAP but are willing to use some code then after you paste your fields together in your computed field class just do what Sitecore does in the GetPlainText() method:
string input = "concatenated string";
return HttpUtility.HtmlDecode(Regex.Replace(input, "<[^>]*>", string.Empty));
or use the util method Sitecore.StringUtil.RemoveTags(text)

Get an XML Element via XPath when attributes are irrelevant

I'm looking for a way to receive a XML Element (the id of an entry) from a YouTube feed (e.g. http://gdata.youtube.com/feeds/api/users/USERNAME/uploads).
The feed looks like this:
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:yt="http://gdata.youtube.com/schemas/2007" gd:etag="W/"DUcFQncyfCp7I2A9WhVUFE4."">
<id>tag:youtube.com,2008:user:USERNAME:uploads</id>
<updated>2012-05-19T14:16:53.994Z</updated>
...
<entry gd:etag="W/"DE8NSX47eCp7I2A9WhVUFE4."">
<id>tag:youtube.com,2008:video:MfPpj7f6Jj0</id>
<published>2012-05-18T13:30:38.000Z</published>
...
I want to get the first tag in entry (tag:youtube.com, 2008 ...).
After googling for some hours and looking through the GDataXML wiki, I'm clueless because neither XPath nor GData could deliver the right element.
My first guess is, they can't ignore the attributes in the feed and entry tags.
A solution using XPath would be great, but one in Objective-C is equally welcome.
You might be having an issue trying to get XPath to work because of the default namespace.
If you just want the first tag in entry, you can use this:
/*/*[name()='entry']/*[1]
If you want the first id specifically, you can use this:
/*/*[name()='entry']/*[name()='id'][1]
Also if you can use XPath 2.0, you can skip the predicate entirely and use * for the namespace prefix:
/*/*:entry/*:id[1]

how to use a hidden input field to store a blog post's set of tags

I have some slightly funky UI for inputting tags for a blog post: as tags are entered into an input field they are wrapped into spans that make them look nice by surrounding them in a stylized box, the end result comes out to be something like this:
http://forr.st/posts/OLs/original
Now, this input field (call it field 1)is not part of the form that gets submitted to the controller (I'm using RoR btw) for two reasons: it contains extraneous html tags, besides the actual tags; also if it was part of the form pressing enter would submit the form instead of triggering the js that wraps the entered tag into a span.
So what I'm doing is when each tag is entered, I copy its value (via js) to a hidden input field that IS part of the tag entry form, and when submitted would contain only the tag values and nothing else. The question is: What should I use as delimiter to separate the tags in the hidden input field. Currently I'm using ';' but if a tag itself contains ; that'd cause problems.
I'm also open to suggestions about the general method of how to keep track of the tags entered into 'field 1'
Thanks a lot,
I would recommend just adding a hidden input for each tag.
<input type="hidden" name="post[tags][]" value="tag_name" />
<input type="hidden" name="post[tags][]" value="tag_name" />
<input type="hidden" name="post[tags][]" value="tag_name" />
then in rails
post.rb
def tags=(value)
tag_array = [*value]
# then just filter these out.
end
I use a similar method with the tokenInput jQuery plugin. But in my case I've placed it inside the form. I solved the problems that you mentioned by capturing the keypress event and preventing it for that input and I ignore the search input value.
The one thing that I really like about keeping it inside the form is how it is managed afterward. I place the hidden tag, name, and a remove 'x' in a span (like you mentioned) and then just remove this tag when the 'x' is clicked. I like this because the name and the hidden_tag are removed at the same time.
Just one other tip. If you can, pass the tag_id in the hidden field. This way you don't have to add the tags attribute add all: <input type="hidden" name="post[tag_ids][]" value="tag_name" />.

How to display data in a textarea using struts application

How do you display data in a 'textarea' using struts application,
This is my code:
<html:textarea property="comments" </html:textarea>
<bean:write name="FormBean" property="comments"/>
where FormBean is my beanclass and comment is a property in beanclass.
But I cannot get it too work.
Thanks in advance for your help.
If you use Struts action forms and you have the html:textarea tag inside your html:form tag (this tag is only valid when nested inside a form tag body) then the following code is all you need:
<html:textarea property="comments" />
Don't know what you are trying to do with bean:write but if you want to display that inside your html:textarea I'm not sure you can. The property attribute is mandatory for the html:textarea tag and will use that as the content.