Top Level Namespace

Includes:
Aerogel::Errors

Defined Under Namespace

Modules: Aerogel, Model

Instance Method Summary collapse

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

#configObject

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_nameObject



1
2
3
# File 'app/helpers/csrf.rb', line 1

def csrf_field_name
  'authenticity_token'
end

#csrf_protected?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/helpers/csrf.rb', line 13

def csrf_protected?
  true
end

#csrf_tokenObject



5
6
7
# File 'app/helpers/csrf.rb', line 5

def csrf_token
  session[:csrf] ||= SecureRandom.hex(32) if defined?(session)
end

#csrf_token_fieldObject



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

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