rbmobile 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +65 -0
- data/lib/mobile_helpers.rb +578 -0
- metadata +83 -0
data/README.markdown
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Ruby JQuery Mobile HAML helper
|
2
|
+
|
3
|
+
A swiss knife for creating a hipster UI like from Apple
|
4
|
+
|
5
|
+
### Description
|
6
|
+
|
7
|
+
This project should help you to create more readable HAML templates for your
|
8
|
+
mobile applications using http://jquerymobile.com framework.
|
9
|
+
|
10
|
+
|
11
|
+
### Documentation
|
12
|
+
|
13
|
+
http://rdoc.info/projects/mfojtik/rbmobile
|
14
|
+
|
15
|
+
### Requirements
|
16
|
+
|
17
|
+
- You should include JQuery library in your project or place this library into
|
18
|
+
'public' folder
|
19
|
+
- You should unzip JQuery mobile inside your 'public' folder:
|
20
|
+
|
21
|
+
$ wget http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.zip -O public/jquery.mobile-1.0b2.zip
|
22
|
+
$ cd public && unzip jquery.mobile-1.0b2.zip
|
23
|
+
|
24
|
+
### Installation
|
25
|
+
|
26
|
+
gem install rbmobile
|
27
|
+
|
28
|
+
### Sinatra
|
29
|
+
|
30
|
+
require 'mobile_helpers'
|
31
|
+
helpers RBMobile::Helpers
|
32
|
+
|
33
|
+
### Rails(?)
|
34
|
+
|
35
|
+
app/helpers/application_helper.rb:
|
36
|
+
require 'mobile_helpers'
|
37
|
+
include RBMobile::Helpers
|
38
|
+
|
39
|
+
### TODO:
|
40
|
+
|
41
|
+
- Finish forms.
|
42
|
+
|
43
|
+
== LICENSE:
|
44
|
+
|
45
|
+
Copyright (c) 20011 Michal Fojtik
|
46
|
+
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
48
|
+
a copy of this software and associated documentation files (the
|
49
|
+
'Software'), to deal in the Software without restriction, including
|
50
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
51
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
52
|
+
permit persons to whom the Software is furnished to do so, subject to
|
53
|
+
the following conditions:
|
54
|
+
|
55
|
+
The above copyright notice and this permission notice shall be
|
56
|
+
included in all copies or substantial portions of the Software.
|
57
|
+
|
58
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
59
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
60
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
61
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
62
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
63
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
64
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
65
|
+
|
@@ -0,0 +1,578 @@
|
|
1
|
+
# This is a jquery.mobile[1] HAML helper to provide an easiest way
|
2
|
+
# to generate mobile application UI
|
3
|
+
#
|
4
|
+
# This helper could be used in Sinatra but also in Rails if properly
|
5
|
+
# included.
|
6
|
+
#
|
7
|
+
# Author:: Michal Fojtik (mi@mifo.sk)
|
8
|
+
# License:: GNU General Public License, version 2 (GPL-2.0)
|
9
|
+
# Copyright:: Michal Fojtik
|
10
|
+
#
|
11
|
+
# [1] http://jquerymobile.com
|
12
|
+
|
13
|
+
|
14
|
+
module RBMobile
|
15
|
+
|
16
|
+
# Assume jquery.mobile installed in public/jquery.mobile-1.0b2/
|
17
|
+
JQUERY_MOBILE_VERSION = 'jquery.mobile-1.0b2'
|
18
|
+
|
19
|
+
# Assume jquery library installed in public/jquery-1.6.2.min.js
|
20
|
+
JQUERY_VERSION = 'jquery-1.6.2'
|
21
|
+
|
22
|
+
# Default configuration
|
23
|
+
@configuration = {
|
24
|
+
:ajax => true
|
25
|
+
}
|
26
|
+
|
27
|
+
# You can disable or enable configuration properties
|
28
|
+
# using:
|
29
|
+
#
|
30
|
+
# RBMobile::config do
|
31
|
+
# enable :property
|
32
|
+
# disable :property
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
def self.config(&block)
|
36
|
+
RBMobile::class_eval(&block) if block_given?
|
37
|
+
@configuration
|
38
|
+
end
|
39
|
+
|
40
|
+
# This method enable given boolean property
|
41
|
+
def self.enable(bool)
|
42
|
+
@configuration[bool] = true
|
43
|
+
end
|
44
|
+
|
45
|
+
# This method disable given boolean property
|
46
|
+
def self.disable(bool)
|
47
|
+
@configuration[bool] = false
|
48
|
+
end
|
49
|
+
|
50
|
+
# This module should be included as a view helper
|
51
|
+
# In Sinatra you need to do following:
|
52
|
+
#
|
53
|
+
# require 'mobile_helpers'
|
54
|
+
# helpers RBMobile::Helpers
|
55
|
+
#
|
56
|
+
# In Rails you should be able to include this module
|
57
|
+
# inside your ApplicationHelper as:
|
58
|
+
#
|
59
|
+
# require 'mobile_helpers'
|
60
|
+
# include RBMobile::Helpers
|
61
|
+
#
|
62
|
+
module Helpers
|
63
|
+
|
64
|
+
# Include all necessary javascript and css libraries for jQuery mobile
|
65
|
+
# You can exclude jQuery itself (in case your project is already including
|
66
|
+
# this library somewhere else by:
|
67
|
+
#
|
68
|
+
# = mobile_include(:no_jquery => true)
|
69
|
+
#
|
70
|
+
# This method should be placed right after %head tag.
|
71
|
+
#
|
72
|
+
def mobile_include(opts={})
|
73
|
+
capture_haml do
|
74
|
+
haml_tag :meta, :name => 'viewport', :content => 'width=device-width, initial-scale=1'
|
75
|
+
haml_tag :link, :rel => 'stylesheet', :href => "/#{JQUERY_MOBILE_VERSION}/#{JQUERY_MOBILE_VERSION}.min.css"
|
76
|
+
unless opts[:no_jquery]
|
77
|
+
haml_tag :script, :type => 'text/javascript', :src => "/#{JQUERY_VERSION}.min.js"
|
78
|
+
end
|
79
|
+
haml_tag :script, :type => 'text/javascript', :src => "/#{JQUERY_MOBILE_VERSION}/#{JQUERY_MOBILE_VERSION}.min.js"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# The jQuery Mobile "page" structure is optimized to support either single
|
84
|
+
# pages, or local internal linked "pages" within a page.
|
85
|
+
#
|
86
|
+
# The goal of this model is to allow developers to create websites using
|
87
|
+
# best practices — where ordinary links will "just work" without any special
|
88
|
+
# configuration — while creating a rich, native-like experience that can't
|
89
|
+
# be achieved with standard HTTP requests
|
90
|
+
#
|
91
|
+
# This helper will generate:
|
92
|
+
#
|
93
|
+
# <div data-role="page">
|
94
|
+
# </div>
|
95
|
+
#
|
96
|
+
# Additional properties that could be set:
|
97
|
+
#
|
98
|
+
# [title] Set 'data-title' attribute
|
99
|
+
# [theme] Change mobile theme ('a'..'f')
|
100
|
+
#
|
101
|
+
# Example usage:
|
102
|
+
#
|
103
|
+
# - page :theme => 'c' do
|
104
|
+
# - header do
|
105
|
+
# %h1 Header
|
106
|
+
#
|
107
|
+
def page(opts={}, &block)
|
108
|
+
opts.merge!(:'data-title' => opts.delete(:title)) if opts[:title]
|
109
|
+
role :page, opts, &block
|
110
|
+
end
|
111
|
+
|
112
|
+
# The header is a toolbar at the top of the page that usually contains the
|
113
|
+
# page title text and optional buttons positioned to the the left and/or
|
114
|
+
# right of the title for navigation or actions.
|
115
|
+
# The title text is normally an H1 heading element but it's possible to use any
|
116
|
+
# heading level (H1-H6) to allow for semantic flexibility. For example, a page
|
117
|
+
# containing multiple mobile 'pages' may use a H1 element on the home 'page' and a
|
118
|
+
# H2 element on the secondary pages. All heading levels are styled identically by
|
119
|
+
# default to maintain visual consistency.
|
120
|
+
#
|
121
|
+
# This helper will generate:
|
122
|
+
#
|
123
|
+
# <div data-role="header">
|
124
|
+
# </div>
|
125
|
+
#
|
126
|
+
# Additional properties that could be set:
|
127
|
+
#
|
128
|
+
# [theme] Change mobile theme ('a'..'f')
|
129
|
+
#
|
130
|
+
def header(opts={}, &block)
|
131
|
+
opts.merge!(:'data-position' => 'inline')
|
132
|
+
role :header, opts, &block
|
133
|
+
end
|
134
|
+
|
135
|
+
# The content block is the main container for your content.
|
136
|
+
#
|
137
|
+
# This helper will generate:
|
138
|
+
#
|
139
|
+
# <div data-role="content">
|
140
|
+
# </div>
|
141
|
+
#
|
142
|
+
# Additional properties that could be set:
|
143
|
+
#
|
144
|
+
# [theme] Change mobile theme ('a'..'f')
|
145
|
+
|
146
|
+
def content(opts={}, &block)
|
147
|
+
role :content, opts, &block
|
148
|
+
end
|
149
|
+
|
150
|
+
# Any page can be presented as a modal dialog by adding the
|
151
|
+
# data-rel="dialog" attribute to the page anchor link. When the "dialog"
|
152
|
+
# attribute is applied, the framework adds styles to add rounded corners,
|
153
|
+
# margins around the page and a dark background to make the "dialog" appear
|
154
|
+
# to be suspended above the page.
|
155
|
+
#
|
156
|
+
# <a href="foo.html" data-rel="dialog">Open dialog</a>
|
157
|
+
#
|
158
|
+
# This helper will generate a block that may contain a dialog:
|
159
|
+
#
|
160
|
+
# <div data-role="dialog">
|
161
|
+
# </div>
|
162
|
+
#
|
163
|
+
# Additional properties that could be set:
|
164
|
+
#
|
165
|
+
# [theme] Change mobile theme ('a'..'f')
|
166
|
+
|
167
|
+
def dialog(opts={}, &block)
|
168
|
+
role :dialog, opts, &block
|
169
|
+
end
|
170
|
+
|
171
|
+
# jQuery Mobile has a very basic navbar widget that is useful for providing
|
172
|
+
# up to 5 buttons with optional icons in a bar , typically within a header
|
173
|
+
# or footer.
|
174
|
+
|
175
|
+
# A navbar is coded as an unordered list of links wrapped in a container
|
176
|
+
# element that has the data-role="navbar" attribute. To set one of links to
|
177
|
+
# the active (selected) state, add class="ui-btn-active" to the anchor. In
|
178
|
+
# this example, we have a two-button navbar in the footer with the "One"
|
179
|
+
# item set to active
|
180
|
+
#
|
181
|
+
# This helper will generate:
|
182
|
+
#
|
183
|
+
# <div data-role="navbar">
|
184
|
+
# <ul>
|
185
|
+
# </ul>
|
186
|
+
# </div>
|
187
|
+
#
|
188
|
+
# Additional properties that could be set:
|
189
|
+
#
|
190
|
+
# [theme] Change mobile theme ('a'..'f')
|
191
|
+
|
192
|
+
def navbar(opts={}, &block)
|
193
|
+
role :navbar, opts do
|
194
|
+
haml_tag :ul do
|
195
|
+
block.call if block_given?
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# This helper will generate a link inside 'navbar' block:
|
201
|
+
#
|
202
|
+
# - navbar do
|
203
|
+
# = navigate_to 'a.html', 'One'
|
204
|
+
# = navigate_to 'b.html', 'Two'
|
205
|
+
#
|
206
|
+
# Will produce:
|
207
|
+
#
|
208
|
+
# <div data-role="navbar">
|
209
|
+
# <ul>
|
210
|
+
# <li><a href="a.html" class="ui-btn-active">One</a></li>
|
211
|
+
# <li><a href="b.html">Two</a></li>
|
212
|
+
# </ul>
|
213
|
+
# </div>
|
214
|
+
#
|
215
|
+
# Additional properties that could be set:
|
216
|
+
#
|
217
|
+
# [theme] Change mobile theme ('a'..'f')
|
218
|
+
# [icon] Icon to use, eg. 'delete' (refer to jquery mobile icon names)
|
219
|
+
# [active] This will make current navigation item active
|
220
|
+
#
|
221
|
+
def navigate_to(url, label, opts={})
|
222
|
+
options = {
|
223
|
+
:href => url
|
224
|
+
}.merge(opts)
|
225
|
+
options.merge!(:class => 'ui-btn-active') if options.delete(:active)
|
226
|
+
options.merge!(:'data-icon' => options.delete(:icon)) if options[:icon]
|
227
|
+
capture_haml do
|
228
|
+
haml_tag :li do
|
229
|
+
haml_tag :a, options do
|
230
|
+
haml_concat label
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
# The footer bar has the same basic structure as the header except it uses the data-role attribute value of footer.
|
237
|
+
#
|
238
|
+
# - footer do
|
239
|
+
# %h4 Footer content
|
240
|
+
#
|
241
|
+
# Will generate:
|
242
|
+
#
|
243
|
+
# <div data-role="footer">
|
244
|
+
# <h4>Footer content</h4>
|
245
|
+
# </div>
|
246
|
+
#
|
247
|
+
# Additional properties that could be set:
|
248
|
+
#
|
249
|
+
# [theme] Change mobile theme ('a'..'f')
|
250
|
+
# [uibar] Include padding on the bar
|
251
|
+
# [fixed] Fixed toolbars will re-appear after you scroll
|
252
|
+
|
253
|
+
def footer(opts={}, &block)
|
254
|
+
opts.merge!(:class => "ui-bar") if opts.delete(:uibar)
|
255
|
+
opts.merge!(:'data-position' => "fixed") if opts.delete(:fixed)
|
256
|
+
role :footer, opts, &block
|
257
|
+
end
|
258
|
+
|
259
|
+
# Occasionally, you may want to visually group a set of buttons together to
|
260
|
+
# form a single block that looks contained like a navigation component. To
|
261
|
+
# get this effect, wrap a set of buttons in a container with the
|
262
|
+
# data-role="controlgroup" attribute — the framework will create a vertical
|
263
|
+
# button group, remove all margins and drop shadows between the buttons, and
|
264
|
+
# only round the first and last buttons of the set to create the effect that
|
265
|
+
# they are grouped together.
|
266
|
+
#
|
267
|
+
# This helper will generate:
|
268
|
+
#
|
269
|
+
# - buttongroup :horizontal do
|
270
|
+
# = button :load, 'load.html', 'Load'
|
271
|
+
# = button :save, 'save.html', 'Save'
|
272
|
+
#
|
273
|
+
# Will produce:
|
274
|
+
#
|
275
|
+
# <div data-role="controlgroup">
|
276
|
+
# <a href="load.html" data-role="button">Load</a>
|
277
|
+
# <a href="save.html" data-role="button">Save</a>
|
278
|
+
# </div>
|
279
|
+
#
|
280
|
+
# Additional properties that could be set:
|
281
|
+
#
|
282
|
+
# [kind] The kind of group. Could be horizontal or vertical. Default: horizontal
|
283
|
+
#
|
284
|
+
def buttongroup(kind=:horizontal, &block)
|
285
|
+
haml_tag :div, :'data-role' => "controlgroup", :'data-type' => "horizontal" do
|
286
|
+
block.call if block_given?
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
# Buttons that are used for navigation should be coded as anchor links, and
|
291
|
+
# those that submit forms as button elements — each will be styled
|
292
|
+
# identically by the framework.
|
293
|
+
#
|
294
|
+
# Example usage:
|
295
|
+
#
|
296
|
+
# = button :save, 'save.html', 'Save', :theme => 'b'
|
297
|
+
# = button :save, 'save.html', 'Save', :ajax => true
|
298
|
+
#
|
299
|
+
# [kind] Define icon used for button
|
300
|
+
# [url] Where to move after click
|
301
|
+
# [label] Text displayed in button
|
302
|
+
# [theme] Change mobile theme ('a'..'f')
|
303
|
+
# [ajax] Overide default AJAX setting
|
304
|
+
|
305
|
+
def button(kind, url, label, opts={})
|
306
|
+
options = {
|
307
|
+
:'data-icon' => kind,
|
308
|
+
:'data-role' => :button,
|
309
|
+
:href => url
|
310
|
+
}.merge(opts)
|
311
|
+
options.merge!(:'data-ajax' => 'false') if not RBMobile::config[:ajax] and not options.delete(:ajax)
|
312
|
+
options.merge!(:'data-theme' => options.delete(:theme)) if options[:theme]
|
313
|
+
capture_haml do
|
314
|
+
haml_tag :a, options do
|
315
|
+
haml_concat label
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
# By default, all buttons in the body content are styled as block-level
|
321
|
+
# element so they fill the width of the screen However, if you want a more
|
322
|
+
# compact button that is only as wide as the text and icons inside, add the
|
323
|
+
# data-inline="true" attribute to the button
|
324
|
+
#
|
325
|
+
# Example usage:
|
326
|
+
#
|
327
|
+
# %p
|
328
|
+
# Click %{inline_button(:save, '/save', 'Save')} to submit changes
|
329
|
+
#
|
330
|
+
def inline_button(kind, url, label, opts={})
|
331
|
+
opts.merge!(:'data-inline' => 'true')
|
332
|
+
button(kind, url, label, opts)
|
333
|
+
end
|
334
|
+
|
335
|
+
# Using multiple column layouts isn't generally recommended on a mobile
|
336
|
+
# device because of the narrow screen width, but there are times where you
|
337
|
+
# may need to place small elements side-by-side (like buttons or navigation
|
338
|
+
# tabs, for example). The jQuery Mobile framework provides a simple way to
|
339
|
+
# build CSS-based columns through a block style class convention called
|
340
|
+
# ui-grid. There are two preset configurations layouts — two-column (using
|
341
|
+
# the class of ui-grid-a), and three-column (using the class of ui-grid-b) —
|
342
|
+
# that can be used in any situation that requires columns. Grids are 100%
|
343
|
+
# width, completely invisible (no borders or backgrounds) and don't have
|
344
|
+
# padding or margins, so they shouldn't interfere with the styles of
|
345
|
+
# elements placed inside them.
|
346
|
+
#
|
347
|
+
# Usage:
|
348
|
+
#
|
349
|
+
# - grid do
|
350
|
+
# - column do
|
351
|
+
# Left content
|
352
|
+
# - column do
|
353
|
+
# Right content
|
354
|
+
#
|
355
|
+
# [columns] How many columns will be used (Default: 2)
|
356
|
+
#
|
357
|
+
def grid(columns=2, &block)
|
358
|
+
@columns = ['ui-block-a', 'ui-block-b', 'ui-block-c'].reverse
|
359
|
+
haml_tag :div, :class => (columns==2) ? 'ui-grid-a' : 'ui-grid-b' do
|
360
|
+
block.call if block_given?
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
# A single grid column
|
365
|
+
#
|
366
|
+
# Usage: see 'grid'
|
367
|
+
#
|
368
|
+
def column(&block)
|
369
|
+
haml_tag :div, :class => @columns.pop do
|
370
|
+
block.call if block_given?
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
# To create a collapsible blocks of content, create a container and add the
|
375
|
+
# data-role="collapsible" attribute.
|
376
|
+
#
|
377
|
+
# Usage:
|
378
|
+
#
|
379
|
+
# - collapse "This content is collapsible" do
|
380
|
+
# %p Some content here!
|
381
|
+
#
|
382
|
+
# <div data-role="collapsible">
|
383
|
+
# <h3>I'm a header</h3>
|
384
|
+
# <p>I'm the collapsible content. By default I'm open and displayed on the page, but you can click the header to hide me.</p>
|
385
|
+
# </div>
|
386
|
+
#
|
387
|
+
# [collapsed] Determine whenever this block is collapsed or not
|
388
|
+
#
|
389
|
+
def collapse(title, opts={}, &block)
|
390
|
+
opts[:'data-collapsed'] = 'true' if opts.delete(:collapsed) or @collapsed
|
391
|
+
role :collapsible, opts do
|
392
|
+
haml_tag :h3 do
|
393
|
+
haml_concat title
|
394
|
+
end
|
395
|
+
block.call
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
# Collapsible sets start with the exact same markup as individual
|
400
|
+
# collapsibles. By adding a parent wrapper with a
|
401
|
+
# data-role="collapsible-set" attribute around a number of collapsibles, the
|
402
|
+
# framework will style these to looks like a visually grouped widget and
|
403
|
+
# make it behave like an accordion so only one section can be open at a
|
404
|
+
# time.
|
405
|
+
#
|
406
|
+
# Example:
|
407
|
+
#
|
408
|
+
# - collapse_set do
|
409
|
+
# - collapse 'This is collapsible' do
|
410
|
+
# Hello world!
|
411
|
+
# - collapse 'This is collapsible' do
|
412
|
+
# Hello world!
|
413
|
+
#
|
414
|
+
def collapse_set(opts={}, &block)
|
415
|
+
@collapsed = true
|
416
|
+
role :'collapsible-set', opts do
|
417
|
+
block.call if block_given?
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
# A list view is coded as a simple unordered list containing linked list
|
422
|
+
# items with a data-role="listview" attribute. jQuery Mobile will apply all
|
423
|
+
# the necessary styles to transform the list into a mobile-friendly list
|
424
|
+
# view with right arrow indicator that fills the full width of the browser
|
425
|
+
# window. When you tap on the list item, the framework will trigger a click
|
426
|
+
# on the first link inside the list item, issue an AJAX request for the URL
|
427
|
+
# in the link, create the new page in the DOM, then kick off a page
|
428
|
+
# transition.
|
429
|
+
#
|
430
|
+
# Example:
|
431
|
+
# - list :theme => 'a', :filter => true do
|
432
|
+
# = divider "This is divider"
|
433
|
+
# - item do
|
434
|
+
# Hello World!
|
435
|
+
# = counter('3')
|
436
|
+
#
|
437
|
+
# [filter] Determine if search filter will show up or not
|
438
|
+
#
|
439
|
+
def list(opts={}, &block)
|
440
|
+
opts[:element] = opts.delete(:ordered) ? :ol : :ul
|
441
|
+
opts[:'data-inset'] = 'true'
|
442
|
+
opts[:'data-split-theme'] = opts.delete(:'split-theme') if opts[:'split-theme']
|
443
|
+
opts[:'data-filter'] = opts.delete(:'filter') ? 'true' : 'false'
|
444
|
+
role :'listview', opts do
|
445
|
+
block.call if block_given?
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
# Same as 'list' but instead of creating a unorder list will create an
|
450
|
+
# ordered list
|
451
|
+
#
|
452
|
+
def ordered_list(opts={}, &block)
|
453
|
+
list(opts.merge(:ordered => true), &block)
|
454
|
+
end
|
455
|
+
|
456
|
+
# A single list item (li).
|
457
|
+
#
|
458
|
+
# Example: See 'list'
|
459
|
+
#
|
460
|
+
# Options:
|
461
|
+
#
|
462
|
+
# [icon] Define the right icon in list
|
463
|
+
# [theme] Change default theme for single list item
|
464
|
+
# [item_icon_url] Allow to display custom (64x64) icon on the left side
|
465
|
+
#
|
466
|
+
def item(opts={}, &block)
|
467
|
+
opts[:'data-icon'] = opts.delete(:icon) if opts[:icon]
|
468
|
+
opts[:'data-theme'] = opts.delete(:theme) if opts[:theme]
|
469
|
+
haml_tag :li, opts do
|
470
|
+
block.call if block_given?
|
471
|
+
haml_tag(:img, :src => opts[:item_icon_url], :class => 'ui-li-icon') if opts[:item_icon_url]
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
# Same as list item ('item') but this will create a 'link' item.
|
476
|
+
#
|
477
|
+
# Example:
|
478
|
+
#
|
479
|
+
# - list do
|
480
|
+
# - link 'a.html', :icon => 'alert' do
|
481
|
+
# This item will send you to a.html
|
482
|
+
#
|
483
|
+
def link(url, opts={}, &block)
|
484
|
+
original_block = block
|
485
|
+
new_block = Proc::new do
|
486
|
+
haml_tag :a, :href => url do
|
487
|
+
original_block.call
|
488
|
+
end
|
489
|
+
end
|
490
|
+
item(opts, &new_block)
|
491
|
+
end
|
492
|
+
|
493
|
+
# This will allow you to create a 'nested' list item.
|
494
|
+
# Instead of showing just one single line in list item this will show a
|
495
|
+
# header and text on bottom.
|
496
|
+
#
|
497
|
+
# Example:
|
498
|
+
#
|
499
|
+
# - list do
|
500
|
+
# - nested_item 'This is item header', :theme => 'b' do
|
501
|
+
# This is item content
|
502
|
+
#
|
503
|
+
def nested_item(title, opts={}, &block)
|
504
|
+
original_block = block
|
505
|
+
new_block = Proc::new do
|
506
|
+
haml_tag :h3 do
|
507
|
+
haml_concat title
|
508
|
+
end
|
509
|
+
original_block.call
|
510
|
+
end
|
511
|
+
item(opts, &new_block)
|
512
|
+
end
|
513
|
+
|
514
|
+
# This will add a small counter on the right side of list item.
|
515
|
+
#
|
516
|
+
# Example:
|
517
|
+
#
|
518
|
+
# - list do
|
519
|
+
# - item do
|
520
|
+
# Active connections
|
521
|
+
# = counter '3'
|
522
|
+
#
|
523
|
+
def counter(value)
|
524
|
+
capture_haml do
|
525
|
+
haml_tag :span, :class => 'ui-li-count' do
|
526
|
+
haml_concat value
|
527
|
+
end
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
# This will allow you to add an thumbnail on right side of list item.
|
532
|
+
#
|
533
|
+
# Example:
|
534
|
+
#
|
535
|
+
# - list do
|
536
|
+
# - item do
|
537
|
+
# = thumb '/images/computer.png'
|
538
|
+
# Computer
|
539
|
+
#
|
540
|
+
def thumb(image_url)
|
541
|
+
capture_haml do
|
542
|
+
haml_tag :image, :class => 'ui-li-thumb', :src => image_url
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
546
|
+
# This will create a list divider. It could be also used to create a contact
|
547
|
+
# list alphabetically sorted.
|
548
|
+
#
|
549
|
+
# - list do
|
550
|
+
# = divider "A"
|
551
|
+
# - item do
|
552
|
+
# Andreas Muller
|
553
|
+
#
|
554
|
+
def divider(title, opts={})
|
555
|
+
opts[:element] = :li
|
556
|
+
capture_haml do
|
557
|
+
role :'list-divider', opts do
|
558
|
+
haml_concat title
|
559
|
+
end
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
private
|
564
|
+
|
565
|
+
def role(name, opts={}, &block)
|
566
|
+
options = {
|
567
|
+
:'data-role' => name
|
568
|
+
}
|
569
|
+
options.merge!(:'data-theme' => opts.delete(:theme)) if opts[:theme]
|
570
|
+
options.merge!(opts)
|
571
|
+
element = options.delete(:element) || :div
|
572
|
+
haml_tag element, options do
|
573
|
+
block.call if block_given?
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
577
|
+
end
|
578
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbmobile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michal Fojtik
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-16 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: haml
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: " A swiss knife to create a hipster UI using jquery.mobile framework.\n Provides set of HAML helpers to make your template more beautifull.\n"
|
36
|
+
email: mi@mifo.sk
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- lib/mobile_helpers.rb
|
45
|
+
- README.markdown
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/mifo/rbmobile
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 53
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 8
|
64
|
+
- 1
|
65
|
+
version: 1.8.1
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.6.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: jquery.mobile HAML helpers
|
82
|
+
test_files: []
|
83
|
+
|