Class: Lurker::BasePresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/lurker/presenters/base_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BasePresenter

Returns a new instance of BasePresenter.



9
10
11
# File 'lib/lurker/presenters/base_presenter.rb', line 9

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/lurker/presenters/base_presenter.rb', line 7

def options
  @options
end

Instance Method Details

#css_pathObject



31
32
33
# File 'lib/lurker/presenters/base_presenter.rb', line 31

def css_path
  File.join(html_directory, "styles.css")
end

#get_bindingObject



19
20
21
# File 'lib/lurker/presenters/base_presenter.rb', line 19

def get_binding
  binding
end

#html_directoryObject



23
24
25
# File 'lib/lurker/presenters/base_presenter.rb', line 23

def html_directory
  options[:url_base_path] || options[:html_directory] || ""
end

#index_path(subdirectory = "") ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/lurker/presenters/base_presenter.rb', line 35

def index_path(subdirectory = "")
  html_path = File.join(html_directory, subdirectory)
  if options[:static_html]
    File.join(html_path, 'index.html')
  else
    html_path
  end
end

#render(*args) ⇒ Object



55
56
57
# File 'lib/lurker/presenters/base_presenter.rb', line 55

def render(*args)
  rendering_controller.render_to_string(*args)
end

#render_erb(erb_name, binding = get_binding) ⇒ Object



13
14
15
16
17
# File 'lib/lurker/presenters/base_presenter.rb', line 13

def render_erb(erb_name, binding = get_binding)
  template_path = path_for_template(erb_name)
  template = ERB.new(File.read(template_path), nil, '-')
  template.result(binding)
end

#tag_with_anchor(tag, content, anchor_slug = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/lurker/presenters/base_presenter.rb', line 44

def tag_with_anchor(tag, content, anchor_slug = nil)
  anchor_slug ||= content.downcase.gsub(' ', '_')
  <<-EOS
  <#{tag} id="#{anchor_slug}">
    <a href="##{anchor_slug}" class="anchor">
      #{content}
    </a>
  </#{tag}>
  EOS
end

#url_base_pathObject



27
28
29
# File 'lib/lurker/presenters/base_presenter.rb', line 27

def url_base_path
  options[:url_base_path] || '/'
end