Make matchit.vim work with erb files? - ruby

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?

Related

Why does Sphinx+MyST put spaces inside HTML tags in the generated output?

I'm new to MyST and Sphinx, so perhaps this has an obvious explanation, but it is not obvious to me. Whenever I use any construct in my Markdown source, such as bold facing or italics or even an html element such as <span>, the result in the formatted HTML output contains spaces inside the HTML tags. For example, an input such as
* **Barcode**: the barcode identifying the item
* **Title**: the title of the item.
* **Author**: the author of the item.
produces this:
Note the space before the :. Inspecting the HTML reveals that the bold-faced element contains unexpected space characters:
Note the spaces inside the <strong>...</strong>. Why is this happening? What am I doing wrong? More importantly, how do I make it stop?
I'm using Sphinx 3.4.3 with myst-parser 0.13.3. My conf.py defines extensions as 'myst_parser', 'sphinx.ext.autodoc', 'sphinx.ext.autosectionlabel', and 'sphinx.ext.napoleon'.

Execute Ruby method on whole page in Middleman

On my Middleman-built website, I need to execute specific Ruby code on the contents of all the pages (templates).
For example, if I had following helper in my config.rb:
def myexample(text)
text.gsub("dog","cat")
end
And in my test.html.haml:
= myexample("Some text about a dog.")
My previewed and generated /test.html would read:
Some text about a cat.
However, I am using several different ways to output text that needs to be modified, most notably through HAML's :markdown filter, so I would prefer not to wrap everything in the = myexample("Text") helper.
I would like to be able to run Ruby code that would take contents of all the pages (preferably) or generated HTML output (if the first option is not possible) as an argument passed to such helper.
Ideally, this code would be run in both the development and build environments, but if that's not possible, build is enough.
Is it possible to do so?
PS. In my specific case, I use a shorthand notation to reference other pages and then I use a regular expression and eval() in order to replace them with relative links from data files.
ActionController::Base has the render_to_string method which will give you the normal HTML output from rendering a partial or page, but in string format. This would allow you to grab the rendered HTML and modify it before finally rendering it for real as an inline template.
In your controller:
rendered_html = render_to_string 'your_template_or_partial'
# do stuff to rendered_html
render inline: rendered_html.html_safe, layout: 'layouts/application'
The html_safe method makes sure Rails knows it's safe to render this as HTML. You do NOT want to do this if user input is being rendered and you have not sanitized it!!!!
If you don't want it to use a layout when rendering, just remove the :layout argument.

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

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.

How can I use erb templates with static files in Sinatra?

I am porting a plain HTML/CSS/JS site to using Sinatra for its backend. The main thing I'm interested in is templates. For now, I have a views directory with HTML files named like "index.html.erb" and a layout named "layout.html.erb". While I would like to use Sinatra's templates with erb, the site I'm working on is static. In other words, my "index.html.erb" does nothave any erb-specific code in it. I only really need the layout in my views directory, for now.
Is there a way that I can move views/index.html.erb to public/index.html but still wrap it in the template views/layout.html?
require 'rubygems'
require 'sinatra'
get '/index.html' do
#page_title = 'Home'
#page_id = 'index.html'
erb :'index.html', { :layout => :'layout.html' }
end
Having read through the Sinatra Readme, there are two main issues that come up in what you are trying to do. First, static files versus template files: Sinatra doesn't have a template renderer for plain HTML, so you'd have to use ERB. Since ERB can be plain HTML, the issue with this is that Sinatra can only use a certain list of file extensions for ERB (and .html isn't one of them).
The second issue is that, in your example code, you would have to have the layout folder different from the templates folder (which Sinatra sees as being the same, which is /views by default).
With this in mind, the closest you could get to what you are asking is the following:
require 'sinatra'
configure do
set :views, root
end
get '/index.html'
erb :'public/index.html', { :layout => :'views/layout.html' }
end
However, this also has a few problems. First, as mentioned, you would have to name your files with the .html.erb extension (or, just .erb if you cut the .html out of the 7th line above). Additionally, anyone could access the raw template file at /index.html.erb on your server. Therefore, the method that you displayed in your original question is the best way to do what you are trying to do in Sinatra without delivering a plain HTML file.
I'm using jquery to accomplish this:
get '/thtml/:path' do
#path = params[:path]
erb :thtml
end
thtml.erb
<%= "<script>$('#main').load('/t-html/#{#path}')</script>" %>
Place the html files are in folder /public/t-html. Don't forget to include jquery in layout.erb.

How can I adjust Textmate syntax highlighting in Smarty literal tags

So I have the Smarty TM bundle installed and active in Textmate, but I have a problem with the way it treats stuff inside of Smarty's literal tags.
As seen in this example: http://pastie.textmate.org/private/v3amipi5ukpg7vlcivixw
If I put Smarty literal tags inside of my HTML script tags, TM sees the stuff within the script tags as JS and highlights it appropriately. If I move those literal tags such that they are around my script, Textmate loses track of the fact that the script tags contain javascript--or even that the script tags are HTML--neither are highlighted.
I hate putting my literal tags inside the script because everything that deals with JS in the editor (for example, I have a TM command to run my JS through JSHint) gets mad at them being there unless I prefix them with JS comments (like in my pasted example). But prefixing them with comments is extra work I don't feel like doing, and causes lots of empty comments in my outputted source.
I have looked at the various lang definitions involved, and just cannot figure out what the heck to do to fix it. Any thoughts?
Thanks,
Jim

Resources