Does Rubymine support I18n string replacement in html.erb files? - internationalization

In .rb-files (like a controller for example) I can hit Option-Enter (on mac) and get the "I18n String value" popup menu.
How can I similarly get help to replace a text in a html.erb view file, like:
<h2>This is a header</h2>
How can I get Rubymine to replace it to
<h2><%= t('header.text') %></h2>
For me right now, nothing happens when I hit Option.Enter in html.erb files.

I see your pain.
But, the closest thing you get - the manual process:
type the single < character, and then
wait a moment to choose the <%= option, which renders ERb tag pair.
Then, select the characters in the string and hit single-quote.
THEN, when you are inside the single quotes, you can Option-Enter to i18n the string.

Related

Allow copy / paste in a text_area field form but remove formatting

I have a text_area field in a form which allows some text formatting through a very simple WYSIWYG (bold / underline / bullet points). This was aimed at having a consistent formatting in the description profile of the users.
<%= l.text_area :access, value: "#{t('.access_placeholder_html')}" %>
Nevertheless, some users usually filled the text_area by copy / pasting directly from their website. And their specific formatting "hypertext links", font size, etc. is after reflected on my website, which makes it a bit dirty.
How can I solve this problem. Ideally I would love that when saving the form it gets rid of all the HTML code that is not allowed instead of not allowing copy / paste. Is this possible? Was wondering if should use Sanitize but if so how? (Sorry new to code, I guess you would have understood).
You didn't say which version of Rails, but you could use #sanitize from ActionView::Helpers::SanitizeHelper module to strip all the HTML formatting. It scrubs HTML from text with a scrubber. The default scrubber allows optional whitelisting of attributes. You can even build your own custom scrubber to modify the string if you need more control over what is output. The module also contains #strip_tags and #strip_links, which are very simple scrubbers that remove all HTML tags and all HTML link tags (leaving the link text).
Note that you can wind up with malformed text if the user's input wasn't valid HTML.
Quick examples from the docs:
// remove all HTML tags except <strong> <em> <a> and the
// <href> attributes from #text
nomarkup_text = sanitize #text, tags: %w(strong em a), attributes: %w(href)
// remove all HTML markup
strip_tags("<b>Bold</b> no more! <a href='more.html'>See more here</a>...")
returns the string Bold no more! See more here...
// remove just the link markup
strip_links('Please e-mail me at me#email.com.')
returns the string Please e-mail me at me#email.com.
More detail at the API page for SantizeHelper

Ruby/Regex: Dealing with strings containing forward slashes and parentheses using gsub and regex

Hi I am using Watir to click through some links. I go to a page, click a link based on its text, and the do it again click a new link. I am locating the links based on their text (it is the only way I can based on their HTML) and need to match the text I pulled from the page to the link. The text that I get contains some extra text not part of the link, so I need to gsub it out. Here is my issue:
String: text = "Nuclear Launch Codes (Levels One/Two)"
Link: Nuclear Launch Codes (Levels One/Two) Blah Blah Blah
Because the links do not always have the exact text I need to locate them like so: /#{text}/
Problem is that returns "Nuclear Launch Codes (Levels One\/Two)"
I though I would gsub the 1st parenthesis and everything after, but I need to keep it because I can have Nuclear Launch Codes (Levels Four/Five)
Is there anyway to modify the string to match the link while ignoring the rest of the link text?
If I understand you correctly, try:
/#{Regexp.escape(text)}/
Or equivalently, if you prefer:
Regexp.new(Regexp.escape(text))
This will automatically escape parentheses, slashes and so on in the text so they are not treated as special regexp characters.

How can I stop Joomla from stripping HTML code from the Contact info?

I've only spent maybe 30 mins searching online for this, and couldn't come up with a decent answer.
But anyway, in Joomla there are normal input fields for the Contacts component, but there's a textarea for the Address.
This would make me assume you can enter multiple lines of address in there, and it would be displayed as separate lines... but it doesn't. Even if I enter line breaks, the output is rendered on one line.
So I try to enter <br> to separate, and upon saving, Joomla strips these tags out.
In the template, the output is being written simply by echoing $this->contact->address
Is there anyway, to explode this input and replace linebreaks with <br> marks?
UPDATE:
For now as a temporary measure I'm able to add HTML code into the database values, which saves and outputs on the front end.
On a separate note, I'm now looking to remove the Subject line from the contact form, without hacking the code. and by using overrides as much as possible. Can anyone help?
Have you tried the Sourcerer extension?
Your question is pretty old, but did you get a solution to this Lee?
To create line-breaks in Joomla, titles, text areas etc. Easiest way to do this is to use the ReReplace extension from NoNumber: http://extensions.joomla.org/extensions/edition/replace/4336
I personally use this to add line break in e.x. menu-item titles, where < br / > aren't allowed and get stripped.
With ReReplacer, you can create a custom tag e.x. {br} and then have ReReplacer replace {br} with < br / >.
So everytime you need to add a line break anywhere in Joomla, where html codes usually get stripped, you can just add {br} to have it add a new line.
Very old question but I've fallen into the same issue and tried to find a more user friendly solution.
You can enter multiple lines in the address textarea, and they are correctly outputted to the HTML page source. But as you know, newlines in HTML are not rendered, they have to be transformed to <br>.
For this PHP has a nice function, nl2br, that inserts a <br> each time it encounters a newline in a string.
So in html\com_contact\contact\default_address.php of your template, replace:
echo $this->contact->address;
with
echo nl2br($this->contact->address);
This would nicely do the job, and allow the user to naturally insert any newline in the contact address textarea that will be correctly rendered with the appropriate <br>; I believe this is quite more user friendly solution than your previous one of the user having to insert -br- tags in the address field.

Make matchit.vim work with erb files?

Matchit.vim currently works with html files.
However when I open up an erb file, it matches < with >, rather than with the matching end tag, even when the cursor is in the middle of the tag word.
I don't care much about matching specific erb tags, but I would like the normal matching of html tags to work when I'm editing erb files.
How can I achieve this?

ALT+ENTER, how to detect the newline in NSString?

in my Cocoa App I have a textfield, where users are supposed to insert a newline by pressing ALT+ENTER. That's fine... when I get the value of it as a NSString and do a NSLog, I actually see that new lines are print.
But when I append the string as part of an html page with appendString and then with loadHTMLString, the new lines are completely ignored in the resulting web page...
Could you kindly give me a suggestion or a documentation link to read? I have really no idea!
Thanks a lot!!!
Plain newline characters are not rendered by browsers.
Replace the newline characters ( \n ) by line break tags ( <br> ).
NSString *newString = [oldString stringByReplacingOccurancesOfString:#"\n" withString:#"<br>"]
The <br> tags will show as newline characters in the webpage.
The issue is that the new lines that exist in the string are inserted literally into the html document source. Newlines in html source do not get rendered literally when the html document is rendered. (Imagine if they did; you'd have many, many extra new lines displayed because of all those new line characters separating html tags.)
Instead you should process the raw text entered by the user to produce html source which will render as what the user entered. So you have to break the text up into paragraphs and then insert appropriate <p></p> tags.
You can use the NSString method enumerateSubstringsInRange:options:usingBlock: with the option NSStringEnumerationByParagraphs. To process each paragraph.
Also, you should to sanitize the data entered by the user. For example you don't want your page to get messed up if the user enters some html tags. Sanatizing the data may be as simple as replacing all the restricted characters in the text with the appropriate html entities, but it depends on what you're doing.

Resources