Module: RubyHtmlApp::Helpers
- Included in:
- HtmlApp
- Defined in:
- lib/rubyhtmlapp/helpers.rb,
lib/rubyhtmlapp/templates/helpers.rb
Instance Method Summary collapse
- #asset_data_uri(path) ⇒ Object
- #find_f(path, pattern) ⇒ Object
- #find_f_each(path, pattern) ⇒ Object
- #include_dir(dir, locals = {}, &block) ⇒ Object
- #render(partial, locals = {}, &block) ⇒ Object
Instance Method Details
#asset_data_uri(path) ⇒ Object
19 20 21 22 |
# File 'lib/rubyhtmlapp/helpers.rb', line 19 def asset_data_uri(path) asset = @sprocket_env[path] Sprockets::Context.new(@sprocket_env, asset.logical_path, asset.pathname).asset_data_uri(path) end |
#find_f(path, pattern) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/rubyhtmlapp/helpers.rb', line 24 def find_f(path, pattern) Find.find(path) do |f| return f if File.basename(f).match(pattern) end nil end |
#find_f_each(path, pattern) ⇒ Object
31 32 33 34 35 |
# File 'lib/rubyhtmlapp/helpers.rb', line 31 def find_f_each(path, pattern) Find.find(path) do |f| yield(f) if File.basename(f).match(pattern) end end |
#include_dir(dir, locals = {}, &block) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rubyhtmlapp/helpers.rb', line 11 def include_dir(dir, locals={}, &block) html = "" find_f_each(File.join(@partial_path, dir), /[0-9a-z]{1}\.html[a-z\.0-9]*$/i) do |f| html.concat(Tilt.new(f).render(self, locals, &block)) end return html end |
#render(partial, locals = {}, &block) ⇒ Object
7 8 9 |
# File 'lib/rubyhtmlapp/helpers.rb', line 7 def render(partial, locals={}, &block) Tilt.new(find_f(@partial_path, /_#{partial}.html[a-z\.0-9]*$/i)).render(self, locals, &block) end |