Sha256: 9f347c96db2f6a698bf7cab96ff265da031379f7ab2ce074a333bf1081c8e7be

Contents?: true

Size: 1002 Bytes

Versions: 7

Compression:

Stored size: 1002 Bytes

Contents

class NeatPages::Helpers::Builder
  def initialize(pagination, base_url, params)
    @pagination = pagination
    @base_url = base_url
    @params = params

    reset_builder
  end

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

    return @builder.html_safe
  end

  def li(content, css_class='', hidden=false)
    attributes = 'class="' + css_class + '" '
    attributes << 'style="display:none"' if hidden

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

  def path_to(page)
    qs = ["page=#{page}"]

    @params.each { |k,v| qs << "#{k}=#{v}" if k != 'page' }

    return @base_url + '?' + qs.join("&")
  end

  def reset_builder
    @builder = ''
  end

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

  def method_missing(*args, &block)
    if @pagination.respond_to? args.first
      return @pagination.send *args, &block
    else
      raise NoMethodError.new("undefined local variable or method '#{args.first}' for #{self.class}")
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
neat-pages-0.1.6 lib/neat_pages/helpers/builder.rb
neat-pages-0.1.5 lib/neat_pages/helpers/builder.rb
neat-pages-0.1.4 lib/neat_pages/helpers/builder.rb
neat-pages-0.1.3 lib/neat_pages/helpers/builder.rb
neat-pages-0.1.2 lib/neat_pages/helpers/builder.rb
neat-pages-0.1.1 lib/neat_pages/helpers/builder.rb
neat-pages-0.1.0 lib/neat_pages/helpers/builder.rb