Module: Bartender::ViewHelpers

Included in:
Page, Partial
Defined in:
lib/bartender/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#asset_url(filename) ⇒ Object

provide the path to the asset



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bartender/view_helpers.rb', line 57

def asset_url(filename)

  asset = Bartender::Asset.new(filename, self.sprockets_env)

  if asset
    return asset.site_path
  else
    $stderr.puts "WARNING: Could not find asset '#{filename}' in #{Bartender::DEFAULTS['assets']} for page #{self.page}"
    return "<!-- WARNING: Could not find asset #{filename} -->"
  end
end

link to the appropriate image



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bartender/view_helpers.rb', line 42

def link_image(filename, options={})
 opts = {}.merge(options) #these are the default options for the stylesheet

  file_path = File.join('images', filename)                                             #this is where the un-compiled asset currently resides
  asset = Bartender::Asset.new(file_path, self.sprockets_env)

  if asset
    return "<img #{opts.to_a.collect{|opt_a| "#{opt_a[0]}=\"#{opt_a[1]}\""}.join(' ')} src=\"#{asset.site_path}\"/>"
  else
    $stderr.puts "WARNING: Could not find image '#{filename}' in #{Bartender::DEFAULTS['assets']} for page #{self.page}"
    return "<!-- WARNING: Could not link img #{filename} -->"
  end
end

link the appropriate js



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bartender/view_helpers.rb', line 27

def link_script(filename, options={})
  opts = {:type => "text/javascript"}.merge(options) #these are the default options for the stylesheet

  file_path = File.join('js', filename)                                             #this is where the un-compiled asset currently resides
  asset = Bartender::Asset.new(file_path, self.sprockets_env)

  if asset
    return "<script #{opts.to_a.collect{|opt_a| "#{opt_a[0]}=\"#{opt_a[1]}\""}.join(' ')} src=\"#{asset.site_path}\"> </script>"
  else
    $stderr.puts "WARNING: Could not find javascript '#{filename}' in #{Bartender::DEFAULTS['assets']} for page #{self.page}"
    return "<!-- WARNING: Could not link javascript #{filename} -->"
  end
end

link the appropriate stylesheet



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bartender/view_helpers.rb', line 12

def link_stylesheet(filename, options={})
  opts = {:rel => "stylesheet", :type => "text/css", :media => "all"}.merge(options) #these are the default options for the stylesheet

  file_path = File.join('css', filename)                                             #this is where the un-compiled asset currently resides
  asset = Bartender::Asset.new(file_path, self.sprockets_env)

  if asset
    return "<link #{opts.to_a.collect{|opt_a| "#{opt_a[0]}=\"#{opt_a[1]}\""}.join(' ')} href=\"#{asset.site_path}\"/>"
  else
    $stderr.puts "WARNING: Could not find stylesheet '#{filename}' in #{Bartender::DEFAULTS['assets']} for page #{self.page}"
    return "<!-- WARNING: Could not link stylesheet #{filename} -->"
  end
end

#partial(filename, variables = {}) ⇒ Object

render a simple partial, use Tilt to render it display an error if the partial isn’t found



7
8
9
# File 'lib/bartender/view_helpers.rb', line 7

def partial(filename, variables={})
  Bartender::Partial.new(filename, self.sprockets_env, variables).to_s
end