New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render Helper w/out Sinatra #1872

Closed
maxlinc opened this Issue Jan 23, 2015 · 3 comments

Comments

Projects
None yet
4 participants
@maxlinc

maxlinc commented Jan 23, 2015

There are definitely parts of Padrino, particularly the helpers, that don't seem to be limited to Sinatra. Their usefulness certainly isn't limited to Sinatra and in many cases the implementation does not require Sinatra.

For example, Middleman, the popular static site generator, uses Padrino-based helpers so you can use those helpers for generating static sites. Other places where they helpers might be useful include Grape, or in Jekyll tag plugins.

I'd like to use them in Thor generators. Those are the generators that power everything from "bundle gem" to "rails generate". I have generators that build documentation or HTML reports, so the Padrino helpers are useful.

I haven't had any trouble with most of the helpers - I've used the Output, Tag and Asset helpers without any problems, but I am not able to easily use the Render helper because I'll get a method missing error.

It seems that Middleman was able to support Padrino's render helper, but had to implement a Sinatra/Padrino compatible render interface.

I'm wondering if either:

  • You could include assumptions in the helper documentation about the interface implemented by the class they are mixed into, like the required signature of render to use the RenderHelpers.

or

  • Fallback to Tilt or some other approach if render is not implemented (i.e. not inside Sinatra or a Sinatra-compatible class).

@ujifgc ujifgc added the enhancement label Jan 23, 2015

@skade

This comment has been minimized.

Show comment
Hide comment
@skade

skade Jan 26, 2015

Member

Another option would be to just implement the shim ourselves. I see the issue that Padrino basically provides the only proper view engine that is halfway independent of a framework in the Ruby space.

Member

skade commented Jan 26, 2015

Another option would be to just implement the shim ourselves. I see the issue that Padrino basically provides the only proper view engine that is halfway independent of a framework in the Ruby space.

@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena Jan 26, 2015

Member

Yeah this is an interesting point I've thought about before, there isn't much that actually ties the helpers module to Sinatra, they are just generally useful HTML generation methods for the most part (except for the rendering and partial logic). Thanks for bringing up this issue for us to think about.

Member

nesquena commented Jan 26, 2015

Yeah this is an interesting point I've thought about before, there isn't much that actually ties the helpers module to Sinatra, they are just generally useful HTML generation methods for the most part (except for the rendering and partial logic). Thanks for bringing up this issue for us to think about.

@maxlinc

This comment has been minimized.

Show comment
Hide comment
@maxlinc

maxlinc Jan 28, 2015

I just switched some Thor code that looked like this:

Crosstest.manifest.scenarios.values.each do |scenario|
  @scenario = scenario
   template 'templates/_test_report.html.tt', "details/#{scenario.slug}.html"
end

Over to this:

template_file = find_in_source_paths("templates/_test_report.html.haml")
template = Tilt.new(template_file)
Crosstest.manifest.scenarios.values.each do |scenario|
  @scenario = scenario
  add_file "details/#{scenario.slug}.html" do
    template.render(self)
  end
end

It was interesting to see that since the Padrino helpers were loaded the template was an instance of Padrino::Rendering::HamlTemplate rather than Tilt::HamlTemplate. This change also means I'm not using Thor's template rendering at all, it's all Tilt/Padrino. The only thing I use from Thor is find_in_source_paths.

I can't use partials, though, because:

NoMethodError: super: no superclass method `render' for #<Crosstest::Command::Generate::Dashboard:0x007fc3b544ad38>
from /opt/boxen/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/padrino-helpers-0.12.4/lib/padrino-helpers/output_helpers.rb:33:in `render'

So I'm not sure about how the Sinatra stuff works, but in terms of pure-Tilt setup it seems like it would just be useful to customize the search paths for templates, but once Padrino finds the partial it seems like Tilt.new(partial).render(locals) would work rather than each Tilt-based framework having a render method.

Hope that makes sense... I wasn't exactly sure what sort of a shim you had in mind.

maxlinc commented Jan 28, 2015

I just switched some Thor code that looked like this:

Crosstest.manifest.scenarios.values.each do |scenario|
  @scenario = scenario
   template 'templates/_test_report.html.tt', "details/#{scenario.slug}.html"
end

Over to this:

template_file = find_in_source_paths("templates/_test_report.html.haml")
template = Tilt.new(template_file)
Crosstest.manifest.scenarios.values.each do |scenario|
  @scenario = scenario
  add_file "details/#{scenario.slug}.html" do
    template.render(self)
  end
end

It was interesting to see that since the Padrino helpers were loaded the template was an instance of Padrino::Rendering::HamlTemplate rather than Tilt::HamlTemplate. This change also means I'm not using Thor's template rendering at all, it's all Tilt/Padrino. The only thing I use from Thor is find_in_source_paths.

I can't use partials, though, because:

NoMethodError: super: no superclass method `render' for #<Crosstest::Command::Generate::Dashboard:0x007fc3b544ad38>
from /opt/boxen/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/padrino-helpers-0.12.4/lib/padrino-helpers/output_helpers.rb:33:in `render'

So I'm not sure about how the Sinatra stuff works, but in terms of pure-Tilt setup it seems like it would just be useful to customize the search paths for templates, but once Padrino finds the partial it seems like Tilt.new(partial).render(locals) would work rather than each Tilt-based framework having a render method.

Hope that makes sense... I wasn't exactly sure what sort of a shim you had in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment