How to use br tag in haml? - haml

I have been trying <br> tag in haml, very unfortunately none of my code are working. How should we use nest for <br> in haml ?
%h1 Helo mate
%br/
whrere are you ?

Your example (%br/) already seems to be correct.
Whether you get a selfclosing tag (<br />) or a standalone tag (<br>) depends on whether your code is interpreted as html or as xhtml, so check which format you need. Xhtml has problems with non-closing tags.
Look here for more info.
Edit: Adding the info from matt's comment. The problem is not the br tag, but the content of the h1 tag being on the same line as the tag as well as on the next line, while the whole content should be nested when the content is more than one line:
%h1
Hello mate
%br/
where are you?

%h1
Hello mate
%br where are you

Related

Why is Padrino rendering my views as escaped text?

I am using slim as my rendering engine. Here is my application.slim
doctype html
html
head
title Hello
body
= yield
Here is my view ("views/welcome/index.slim")
h1 Hello
The application.slim is being rendered correctly, but I see "< h1>Hello< /h1>" on the page.
Any ideas?
I found the answer. You have to use == when rendering a partial if you don't want it escaped. Can't believe I didn't see that in the docs.

How to use <br /> in a placeholder on Rails 3?

I have a textarea which is has Markdown support and I would like to show a placeholder to show what sort of formatting Markdown likes but putting <br /> in the placeholder shows <br /> in the text. I would prefer it to make a new line if this is possible.
I am using Rails 3, below is the code I am using:
<%= f.text_area :info, :placeholder => "if you want you can <br /> add a link by doing this: [text](http://link.com) it's pretty neat aye? or you could use bold by doing this: **bold text is cool**" %>
According to the specification, the placeholder attribute can't contain any line breaks or carriage returns.
As Logan says, though you can find some hacks in the similar question here:
Can you have multiline HTML5 placeholder text in a <textarea>?
Here are some more related hacks to multiline placeholders, I followed the example in the answer below to do my workaround:
Insert line break inside placeholder attribute of a textarea?
For rails, I thought this was useful if you want a gem to deal with placeholders:
jquery-placeholder-rails.
However, you'll need the forked version of jQuery-placeholder that supports newline: jQuery-Placeholder-Newlines

How to make html code in erb tag not escaped

I have some simple erb code in one of my views in a rails project.
<%= comment.body %>
I'd like the html tags in the comment.body to be preserved as they have formatting information. I've verified that the text is saved in the database properly like
<b>hello</b>
However it turns out on the page to be <b>hello</b> not hello as I expect.
How could this be? I'm not using <%= h to escape the html code.
How do I make it not escaping? I'm using rails 3. Does this matter?
You can also use sanitize.
<%= sanitize(comment.body) %>
sanitize will leave html code but escape javascript.
Rails 3 now automatically escapes your output.
To unescape the text and use the actual tags, use raw(...):
<%= raw(comment.body) %>
However, be careful with this, as it will allow any tags, including scripts (potentially malicious). A safer option might be to have users use markdown-formatted text or something similar, rather than allowing raw HTML tags.

CSS locator for corresponding xpath for selenium

The some part of the html of the webpage which I'm testing looks like this
<div id="twoWideCallouts">
<div class="callout">
<a target="_blank" href="http://facebook.com">Facebook</a>
</div>
<div class="callout last">
<a target="_blank" href="http://youtube.com">Youtube</a>
</div>
I've to check using selenium that when I click on text, the URL opened is the same that is given in href and not error page.
Using Xpath I've written the following command
//i is iterator
selenium.getAttribute("//div[contains(#class, 'callout')]["+i+"]/a/#href")
However, this is very slow and for some of the links doesn't work. By reading many answers and comments on this site I've come to know that CSS loactors are faster and cleaner to maintain so I wrote it again as
css = div:contains(callout)
Firstly, I'm not able to reach to the anchor tag.
Secondly, This page can have any number of div where id = callout. Using xpathcount i can get the count of this, and I'll be iterating on that count and performing the href check. How can something similar be done using CSS locator?
Any help would be appreciated.
EDIT
I can click on the link using the locator css=div.callout a, but when I try to read the href value using String str = "css=div.callout a[href]";
selenium.getAttribute(str);. I get the Error - element not found. Console description is given below.
19:12:33.968 INFO - Command request: getAttribute[css=div.callout a[href], ] on session
19:12:33.993 INFO - Got result: ERROR: Element css=div.callout a[href not found on session
I tried to get the href attribute using xpath like this
"xpath=(//div[contains(#class, 'callout')])["+1+"]/a/#href" and it worked fine.
Please tell me what should be the corresponding CSS locator for this.
It should be -
css = div:contains(callout)
Did you notice ":" instead of "." you used?
For CSSCount this might help -
http://www.eviltester.com/index.php/2010/03/13/a-simple-getcsscount-helper-method-for-use-with-selenium-rc/
#
On a different note, did you see proposal of new selenium site on area 51 - http://area51.stackexchange.com/proposals/4693/selenium.
#
To read the sttribute I used css=div.callout a#href and it worked. The problem was with use of square brackets around attribute name.
For the first part of your question, anchor your identifier on the hyperlink:
css=a[href=http://youtube.com]
For achieving a count of elements in the DOM, based on CSS selectors, here's an excellent article.

disable adding of <p></p> tags in fckeditor

how to disable automatic adding of <p></p> tags in Fckeditor.
When i try to get any post data from fckeditor, it gives me the data wrapped in
how do i remove/disable those <p></p>
Thanks in advance for any suggestions and reply
Too late, but will help others reaching this page via search engines, like I found it.
<?php
include_once('fckeditor/fckeditor.php');
$oFCKeditor = new FCKeditor('description');
$oFCKeditor->BasePath = '/fckeditor/';
$oFCKeditor->Value = 'some text';
$oFCKeditor->Config['EnterMode'] = 'br'; // turn off auto <p> tags wrapping content
$oFCKeditor->Create();
?>
Refer http://www.tequilafish.com/2008/09/12/fckeditor-remove-p-tags-from-wrapping-your-content/
Adding to the previous answer, If you're using ColdFusion rich text area (which used fckeditor), you can disable the <p> tags by setting EnterMode to br in fckconfig.js