Class: Skyrocket::ErbProcessor

Inherits:
Object
  • Object
show all
Includes:
Processor
Defined in:
lib/skyrocket/erb_processor.rb

Instance Method Summary collapse

Methods included from Processor

#asset_factory, asset_factory=, #base_url, base_url=, #post_process_name, #process, #process?

Instance Method Details

#content_for(key) ⇒ Object



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

def content_for(key)
  # swap current ERB output buffer with a 'fake' buffer
  # otherwise calling yield will write contents of block
  # to ERB results output
  old = @out
  @out = ''
  results = yield.chomp
  @out = old
  cf[key.to_sym] = results
  nil
end

#extensionObject



7
# File 'lib/skyrocket/erb_processor.rb', line 7

def extension; '.erb'; end

#get_bindingObject



26
27
28
# File 'lib/skyrocket/erb_processor.rb', line 26

def get_binding
  binding
end

#href(path) ⇒ Object



53
54
55
# File 'lib/skyrocket/erb_processor.rb', line 53

def href(path)
  resolve(path)
end

#image_tag(path, options) ⇒ Object



48
49
50
51
# File 'lib/skyrocket/erb_processor.rb', line 48

def image_tag(path, options)
  opt_s = to_opt_s(options)
  "<img src=\"#{resolve(path)}\"#{opt_s} />"
end

#javascript_include_tag(path) ⇒ Object



39
40
41
# File 'lib/skyrocket/erb_processor.rb', line 39

def javascript_include_tag(path)
  "<script src=\"#{resolve(path)}\"></script>"
end

#layout(name) ⇒ Object



30
31
32
33
# File 'lib/skyrocket/erb_processor.rb', line 30

def layout(name)
  @layout = name
  nil
end


43
44
45
46
# File 'lib/skyrocket/erb_processor.rb', line 43

def link_to(content, path, options = Hash.new)
  opt_s = to_opt_s(options)
  "<a href=\"#{resolve(path)}\"#{opt_s}>#{content}</a>"
end

#process_contents(contents, name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/skyrocket/erb_processor.rb', line 9

def process_contents(contents, name)
  template = ERB.new(contents, nil, '-', '@out')
  results = template.result(get_binding { |name=nil| '' })
  if(@layout)
    outer_contents = asset_factory.from_name(@layout).raw
    outer_template = ERB.new(outer_contents, nil, '-', '@out')
    results = outer_template.result(get_binding do |name=nil|
      if name == nil
        results
      else
        cf[name.to_sym] || ''
      end
    end)
  end
  results
end

#render(asset_name) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/skyrocket/erb_processor.rb', line 69

def render(asset_name)
  contents = asset_factory.from_name(asset_name).raw
  old = @out # save current ERB buffer
  @out = ''
  template = ERB.new(contents, nil, '-', '@out')
  results = template.result(get_binding do |name=nil|
    if name == nil
      results
    else
      cf[name.to_sym]
    end
  end)
  @out = old
  results
end


35
36
37
# File 'lib/skyrocket/erb_processor.rb', line 35

def stylesheet_link_tag(path)
  "<link rel=\"stylesheet\" href=\"#{resolve(path)}\">"
end