Module: JqmHelper

Includes:
ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper
Included in:
NavBuilder
Defined in:
lib/jqm_helper.rb,
lib/jqm_helper/railtie.rb,
lib/jqm_helper/nav_builder.rb,
lib/jqm_helper/tag_helpers.rb

Defined Under Namespace

Classes: NavBuilder, Railtie

Instance Method Summary collapse

Instance Method Details

#back_button(options = {}) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/jqm_helper/tag_helpers.rb', line 102

def back_button(options = {})
  defaults = {
      data: {
          rel: :back
      }
  }
  backwards_button('Back', '#', make_options(defaults, options))
end

#backward_button(text, href, options = {}) ⇒ Object Also known as: backwards_button



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/jqm_helper/tag_helpers.rb', line 88

def backward_button(text, href, options = {})
  defaults = {
      :href => href,
      :data => {
          :role => :button,
          :icon => 'arrow-l',
          :direction => 'reverse'
      }
  }

  (:a, raw(text), make_options(defaults, options))
end

#dialog_button(text, href, options = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/jqm_helper/tag_helpers.rb', line 64

def dialog_button(text, href, options = {})
  defaults = {
      data: {
          rel: :dialog,
          transition: :slidedown,
      }
  }
  jqm_button(text, href, make_options(defaults, options))
end

#forward_button(text, href, options = {}) ⇒ Object Also known as: forwards_button



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/jqm_helper/tag_helpers.rb', line 74

def forward_button(text, href, options = {})
  defaults = {
      :href => href,
      :data => {
          :role => :button,
          :icon => 'arrow-r',
          :iconpos => 'right'
      }
  }

  (:a, raw(text), make_options(defaults, options))
end

#jqm_button(text, href_or_options, options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jqm_helper/tag_helpers.rb', line 45

def jqm_button(text, href_or_options, options = {})
  defaults = {
      data: {
          role: :button,
          prefetch: :true
      }
  }
  if href_or_options.is_a? Hash
    options = href_of_options
  else
    # we allow href to be overridden by options.  Convenient or a pain?
    defaults[:href] = href_or_options
  end

  defaults[:class] = 'notext' if text.blank? || text==' '

  (:a, raw(text), make_options(defaults, options))
end

#jqm_page(title, options = {}, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jqm_helper/tag_helpers.rb', line 3

def jqm_page(title, options = {}, &block)
  defaults = {
      :class => "#{title.downcase}_page",
      :id => "#{title.downcase}_page",
      :data => {
          :role => 'page',
          :title => title.capitalize,
      }
  }

  script = ''

  #session.delete('load_resource') { [] }.each do |name, resource|
  #  o = {}
  #  logger.warn "loading resource: #{name}, #{resource.last}. #{resource.first}"
  #  o[name] = resource.first.where({_id: resource.last})
  #  script << "window.load_resource(#{resource.to_json}');\n"
  #end

  # todo: assets version gemified
  (:div, raw(%Q{
                <meta name="assets_version" content="#{1 || Brickbook::Application.config.assets.version}"/>
                #{csrf_meta_tags}
                <!--<script type='text/javascript'>#{script}</script>-->
                #{capture(&block)}
                        }), make_options(defaults, options))
end

#make_options(defaults, custom) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jqm_helper.rb', line 16

def make_options(defaults, custom)

  [defaults, custom].each do |options|
    # standardize keys:
    if data = options.delete(:data)
      data.each do |k, v|
        options[:"data-#{k}"] = v
      end
    end
  end

  options = defaults.merge(custom)
  options.delete(:'data-prefetch') if options[:'data-prefetch'] == false
  options
end

someday: options



3
4
5
6
# File 'lib/jqm_helper/nav_builder.rb', line 3

def nav_for(page, &block) # someday: options
  builder = NavBuilder.new(page)
   :div, capture(builder, &block), make_options({data: {role: 'controlgroup', type: 'horizontal'}}, {})
end

#slider_tag(name, label) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/jqm_helper/tag_helpers.rb', line 111

def slider_tag(name, label)
  raw %Q{
 <div data-role="fieldcontain" style="border: 0; margin: 0; padding: 1em 0 0 0;">
             <label style="" for="#{name}">#{label}</label>
             <select name="#{name}" id="#{name}" data-role="slider">
               <option value="no">Off</option>
               <option value="yes">On</option>
             </select>
           </div>
 }
end