Class: Whisper::Page::HTMLBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/whisper/page.rb

Overview

an environment for erb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entryset, config, router, page_vars, url_vars, format) ⇒ HTMLBuilder

Returns a new instance of HTMLBuilder.



42
43
44
45
46
47
48
49
50
# File 'lib/whisper/page.rb', line 42

def initialize entryset, config, router, page_vars, url_vars, format
  @entryset = entryset
  @config = config
  @router = router
  @page_vars = page_vars
  @url_vars = url_vars
  @format = format
  @content = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/whisper/page.rb', line 52

def method_missing m, *a
  if @page_vars.member?(m) && a.empty?
    @page_vars[m]
  elsif @config.respond_to? m
    @config.send m, *a
  else
    raise NoMethodError, "undefined method '#{m}' for #{self.class}. Possible ERB error."
  end
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



40
41
42
# File 'lib/whisper/page.rb', line 40

def content
  @content
end

#entrysetObject

Returns the value of attribute entryset.



40
41
42
# File 'lib/whisper/page.rb', line 40

def entryset
  @entryset
end

Class Method Details

.install(content, filename) ⇒ Object



82
# File 'lib/whisper/page.rb', line 82

def self.install content, filename; eval content, binding, filename end

Instance Method Details

#full_url_for(opts = {}) ⇒ Object



64
# File 'lib/whisper/page.rb', line 64

def full_url_for opts={}; @config.public_url_root + url_for(opts) end

#full_url_for_current(opts = {}) ⇒ Object



67
# File 'lib/whisper/page.rb', line 67

def full_url_for_current opts={}; @config.public_url_root + url_for_current(opts) end


69
70
71
72
73
# File 'lib/whisper/page.rb', line 69

def link_to text, opts={}
  raise "bad: #{text.inspect}, #{opts.inspect}" unless opts.is_a?(Hash)
  html_opts = (opts[:html_opts] || {}).map { |k, v| "#{k}=\"#{v}\"" }.join(" ")
  "<a #{html_opts} href=\"" + url_for(opts) + "\">#{text}</a>"
end


75
76
77
78
# File 'lib/whisper/page.rb', line 75

def link_to_current text, opts={}
  html_opts = (opts[:html_opts] || {}).map { |k, v| "#{k}=\"#{v}\"" }.join(" ")
  "<a #{html_opts} href=\"" + url_for_current(opts) + "\">#{text}</a>"
end

#my_bindingObject



80
# File 'lib/whisper/page.rb', line 80

def my_binding; binding end

#url_for(opts = {}) ⇒ Object

utility methods for templates. TODO: move to router



63
# File 'lib/whisper/page.rb', line 63

def url_for opts={}; @router.url_for({ :format => @format }.merge(opts)) end

#url_for_current(opts = {}) ⇒ Object



66
# File 'lib/whisper/page.rb', line 66

def url_for_current opts={}; url_for @url_vars.merge(opts) end