Top Level Namespace
- Includes:
- Aerogel::Errors
Defined Under Namespace
Instance Method Summary collapse
-
#assets(filename = :application) ⇒ Object
Include styles and javascript tags for assets grouped by scope.
-
#config ⇒ Object
Quick access to config from views and routes.
- #csrf_field_name ⇒ Object
- #csrf_protected? ⇒ Boolean
- #csrf_token ⇒ Object
- #csrf_token_field ⇒ Object
- #find_template(views, name, engine, &block) ⇒ Object
-
#h(str) ⇒ Object
Escapes html string.
-
#link_to(url, text = url, opts = {}) ⇒ Object
Creates <a href=”..>…</a> tag.
- #logger(name = nil) ⇒ Object
- #output_capture(inner_block = nil, &block) ⇒ Object
- #output_concat(text) ⇒ Object
-
#partial(name, opts = {}) ⇒ Object
Renders partial erb template.
-
#tag(name, *args, &block) ⇒ Object
Creates tag.
-
#view(name, *args) ⇒ Object
Renders erb template.
Instance Method Details
#assets(filename = :application) ⇒ Object
Include styles and javascript tags for assets grouped by scope.
Intended use is either:
<%= assets %> # for application assets
or:
<% assets 'controller/name' %> # for controller specific assets
8 9 10 11 |
# File 'app/helpers/assets.rb', line 8 def assets( filename = :application ) (stylesheet_tag filename.to_s) + (javascript_tag filename.to_s) end |
#config ⇒ Object
Quick access to config from views and routes
3 4 5 |
# File 'app/helpers/config.rb', line 3 def config Aerogel.config end |
#csrf_field_name ⇒ Object
1 2 3 |
# File 'app/helpers/csrf.rb', line 1 def csrf_field_name 'authenticity_token' end |
#csrf_protected? ⇒ Boolean
13 14 15 |
# File 'app/helpers/csrf.rb', line 13 def csrf_protected? true end |
#csrf_token ⇒ Object
5 6 7 |
# File 'app/helpers/csrf.rb', line 5 def csrf_token session[:csrf] ||= SecureRandom.hex(32) if defined?(session) end |
#csrf_token_field ⇒ Object
9 10 11 |
# File 'app/helpers/csrf.rb', line 9 def csrf_token_field tag :input, type: 'hidden', name: csrf_field_name, value: csrf_token end |
#find_template(views, name, engine, &block) ⇒ Object
1 2 3 |
# File 'app/helpers/core.rb', line 1 def find_template(views, name, engine, &block) Array(views).each { |v| super(v, name, engine, &block) } end |
#h(str) ⇒ Object
Escapes html string.
5 6 7 |
# File 'app/helpers/render.rb', line 5 def h( str ) Rack::Utils.escape_html(str) end |
#link_to(url, text = url, opts = {}) ⇒ Object
Creates <a href=”..>…</a> tag.
27 28 29 |
# File 'app/helpers/tags.rb', line 27 def link_to( url, text = url, opts = {} ) tag :a, text, opts.merge( href: url ) end |
#logger(name = nil) ⇒ Object
5 6 7 8 9 10 11 |
# File 'app/helpers/core.rb', line 5 def logger( name = nil ) if name.nil? env['rack.logger'] else env['rack.logger.'+name.to_s] or raise("Logger with name '#{name}' is not registered") end end |
#output_capture(inner_block = nil, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/output_buffer.rb', line 11 def output_capture( inner_block = nil, &block ) inner_block = block if inner_block.nil? if self.respond_to?(:is_haml?) && is_haml? && (block_is_haml?(inner_block) rescue false) # haml capture_haml(nil, &block) elsif Aerogel::Render::OutputBuffer.block_is_erb? block # erb Aerogel::Render::OutputBuffer.capture( &block ) else block.call end end |
#output_concat(text) ⇒ Object
1 2 3 4 5 6 7 8 9 |
# File 'app/helpers/output_buffer.rb', line 1 def output_concat( text ) if self.respond_to?(:is_haml?) && is_haml? haml_concat(text) elsif !Aerogel::Render::OutputBuffer.buffer.nil? # has_erb_buffer? Aerogel::Render::OutputBuffer.buffer.concat text else # theres no template to concat, return the text directly text end end |
#partial(name, opts = {}) ⇒ Object
Renders partial erb template.
17 18 19 20 21 22 |
# File 'app/helpers/render.rb', line 17 def partial( name, opts = {} ) name_parts = name.to_s.split('/') name_parts[-1] = '_'+name_parts[-1]+".html" opts[:layout] = false erb name_parts.join('/').to_sym, opts end |
#tag(name, *args, &block) ⇒ Object
Creates tag.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/tags.rb', line 3 def tag( name, *args, &block ) if block_given? content = output_capture(&block) elsif args.first.is_a? String content = args.shift end attrs = args.shift || {} # t_attrs = attrs.map{|k,v| v.nil? ? " #{k}" : " #{k}=\"#{h(v)}\""} t_attrs = attrs.map{|k,v| v.nil? ? " #{k}" : " #{k}=\"#{(v)}\""} if content output = "<#{name}#{t_attrs.join}>"+content+"</#{name}>" else output = "<#{name}#{t_attrs.join}/>" end if Aerogel::Render::OutputBuffer.block_is_template?(block) output_concat(output) return nil else return output end end |
#view(name, *args) ⇒ Object
Renders erb template.
11 12 13 |
# File 'app/helpers/render.rb', line 11 def view( name, *args ) erb( "#{name}.html".to_sym, *args ) end |