Class: NeatPages::Helpers::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/neat_pages/helpers/builder.rb

Overview

************************************************************************************* Builder will help build a string of html output. *************************************************************************************

Direct Known Subclasses

Navigation, Status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pagination, request) ⇒ Builder

Returns a new instance of Builder.



10
11
12
13
14
15
16
17
# File 'lib/neat_pages/helpers/builder.rb', line 10

def initialize(pagination, request)
  @pagination = pagination
  @base_url = generate_base_url_from_request(request)
  @params = request.env['action_dispatch.request.query_parameters']
  @params.delete('utf8')

  reset_builder
end

Instance Attribute Details

#paginationObject (readonly)

Returns the value of attribute pagination.



5
6
7
# File 'lib/neat_pages/helpers/builder.rb', line 5

def pagination
  @pagination
end

Instance Method Details

#b(str = '') ⇒ Object



19
20
21
22
23
# File 'lib/neat_pages/helpers/builder.rb', line 19

def b(str='')
  @builder << str

  @builder.html_safe
end

#li(content, css_class = '', options = {}) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/neat_pages/helpers/builder.rb', line 25

def li(content, css_class='', options={})
  options = { hidden: false }.merge(options)

  attributes = ' class="' + css_class + '"' if not css_class.empty?
  attributes << ' style="display:none"' if options[:hidden]

  b "<li#{attributes}>#{content}</li>"
end

#path_to(page) ⇒ Object



34
35
36
37
38
# File 'lib/neat_pages/helpers/builder.rb', line 34

def path_to(page)
  qs = @params.map { |k,v| "#{k}=#{v}" if k != 'page' }.compact.join('&')

  "#{@base_url}?#{qs}" + (qs.empty? ? '' : '&') + "page=#{page}"
end

#reset_builderObject



40
41
42
# File 'lib/neat_pages/helpers/builder.rb', line 40

def reset_builder
  @builder = ''
end

#t(text_path) ⇒ Object



44
45
46
# File 'lib/neat_pages/helpers/builder.rb', line 44

def t(text_path)
  (defined? I18n) ? I18n.t("neat_pages.#{text_path}") : text_path
end