Sha256: 5de6d94f2c75176892909c85304dae3cb83041752d33471db82adf5643f3bc56

Contents?: true

Size: 1.63 KB

Versions: 6

Compression:

Stored size: 1.63 KB

Contents

module Picky

  # This class provides a few view helpers.
  #
  class Helper
    
    # Returns a standard search interface for easy starting.
    #
    # ... aka scaffolding ;)
    #
    # Options:
    #  * button: The search button text.
    #  * no_results: The text shown when there are no results.
    #  * more: The text shown when there are more than X results.
    #
    # Usage, in Views:
    #
    #   = Picky::Helper.interface :button => 'Go go go!'
    #
    #
    def self.interface options = {}
<<-HTML
<section class="picky">
  #{input(options)}
  #{results(options)}
</section>
HTML
    end
    def self.input options = {}
      search_button_text = options[:button]      || 'search'
      placeholder_text   = options[:placeholder] || 'Search here...'
<<-HTML
<form class="empty" onkeypress="return event.keyCode != 13;">
    <div class="status"></div>
    <input type="search" placeholder="#{placeholder_text}" autocorrect="off" class="query"/>
    <a class="reset" title="clear"></a>
  <input type="button" value="#{search_button_text}"/>
</form>
HTML
    end
    def self.results options = {}
      no_results        = options[:no_results] || 'Sorry, no results found!'
      more_allocations  = options[:more]       || 'more'
<<-HTML
<div class="results"></div>
<div class="no_results">#{no_results}</div>
<div class="allocations">
  <ol class="shown"></ol>
  <ol class="more">#{more_allocations}</ol>
  <ol class="hidden"></ol>
</div>
HTML
    end
    
    # Returns a cached version if you always use a single language.
    #
    def self.cached_interface options = {}
      @interface ||= interface(options).freeze
    end
    
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
picky-client-4.8.1 lib/picky-client/helper.rb
picky-client-4.8.0 lib/picky-client/helper.rb
picky-client-4.7.0 lib/picky-client/helper.rb
picky-client-4.6.6 lib/picky-client/helper.rb
picky-client-4.6.5 lib/picky-client/helper.rb
picky-client-4.6.4 lib/picky-client/helper.rb