rbmobile 0.0.3 → 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/mobile_helpers.rb +282 -26
  2. metadata +3 -4
@@ -14,14 +14,24 @@
14
14
  module RBMobile
15
15
 
16
16
  # Assume jquery.mobile installed in public/jquery.mobile-1.0b2/
17
+ # NOTE: I tested this helper set with version 1.0b2 but you can of course
18
+ # use any latest/older version at your own risk.
19
+ # Please don't fill any tickets regarding to the jquery.mobile when
20
+ # you're using other version than 1.0b2. Only tickets that will be not
21
+ # deleted will be those with attached patch :-)
22
+ #
17
23
  JQUERY_MOBILE_VERSION = 'jquery.mobile-1.0b2'
18
24
 
19
25
  # Assume jquery library installed in public/jquery-1.6.2.min.js
26
+ # I don't think that jquery.mobile rely on exact JQuery version.
20
27
  JQUERY_VERSION = 'jquery-1.6.2'
21
28
 
22
29
  # Default configuration
23
30
  @configuration = {
24
- :ajax => true
31
+ :ajax => true,
32
+ :mobile_css_path => "/#{JQUERY_MOBILE_VERSION}/#{JQUERY_MOBILE_VERSION}.min.css",
33
+ :mobile_js_path => "/#{JQUERY_MOBILE_VERSION}/#{JQUERY_MOBILE_VERSION}.min.js",
34
+ :jquery_path => "/#{JQUERY_VERSION}.min.js"
25
35
  }
26
36
 
27
37
  # You can disable or enable configuration properties
@@ -47,6 +57,30 @@ module RBMobile
47
57
  @configuration[bool] = false
48
58
  end
49
59
 
60
+ # Set URI path to jquery.mobile CSS file
61
+ #
62
+ # Default: "/#{JQUERY_MOBILE_VERSION}/#{JQUERY_MOBILE_VERSION}.min.css"
63
+ #
64
+ def self.jquery_mobile_css_path(path)
65
+ @configuration[:mobile_css_path] = path
66
+ end
67
+
68
+ # Set URI path to jquery.mobile javascript file
69
+ #
70
+ # Default: "/#{JQUERY_MOBILE_VERSION}/#{JQUERY_MOBILE_VERSION}.min.js"
71
+ #
72
+ def self.jquery_mobile_js_path(path)
73
+ @configuration[:mobile_js_path] = path
74
+ end
75
+
76
+ # Set URI path to jquery library
77
+ #
78
+ # Default: "/#{JQUERY_VERSION}.min.js"
79
+ #
80
+ def self.jquery_path(path)
81
+ @configuration[:jquery_path] = path
82
+ end
83
+
50
84
  # This module should be included as a view helper
51
85
  # In Sinatra you need to do following:
52
86
  #
@@ -69,14 +103,17 @@ module RBMobile
69
103
  #
70
104
  # This method should be placed right after %head tag.
71
105
  #
106
+ # Additional options:
107
+ #
108
+ # [:scale] Set initial scale of display (Default: 1)
109
+ # [:no_jquery] Disable inclusion of JQuery library
110
+ #
72
111
  def mobile_include(opts={})
73
112
  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"
113
+ haml_tag :meta, :name => 'viewport', :content => "width=device-width, initial-scale=#{opts[:scale] || '1'}"
114
+ haml_tag :script, :type => 'text/javascript', :src => RBMobile::config[:jquery_path] unless opts[:no_jquery]
115
+ haml_tag :link, :rel => 'stylesheet', :href => RBMobile::config[:mobile_css_path]
116
+ haml_tag :script, :type => 'text/javascript', :src => RBMobile::config[:mobile_js_path]
80
117
  end
81
118
  end
82
119
 
@@ -95,8 +132,8 @@ module RBMobile
95
132
  #
96
133
  # Additional properties that could be set:
97
134
  #
98
- # [title] Set 'data-title' attribute
99
- # [theme] Change mobile theme ('a'..'f')
135
+ # [:title] Set 'data-title' attribute
136
+ # [:theme] Change mobile theme ('a'..'f')
100
137
  #
101
138
  # Example usage:
102
139
  #
@@ -125,7 +162,7 @@ module RBMobile
125
162
  #
126
163
  # Additional properties that could be set:
127
164
  #
128
- # [theme] Change mobile theme ('a'..'f')
165
+ # [:theme] Change mobile theme ('a'..'f')
129
166
  #
130
167
  def header(opts={}, &block)
131
168
  opts.merge!(:'data-position' => 'inline')
@@ -141,7 +178,7 @@ module RBMobile
141
178
  #
142
179
  # Additional properties that could be set:
143
180
  #
144
- # [theme] Change mobile theme ('a'..'f')
181
+ # [:theme] Change mobile theme ('a'..'f')
145
182
 
146
183
  def content(opts={}, &block)
147
184
  role :content, opts, &block
@@ -162,7 +199,7 @@ module RBMobile
162
199
  #
163
200
  # Additional properties that could be set:
164
201
  #
165
- # [theme] Change mobile theme ('a'..'f')
202
+ # [:theme] Change mobile theme ('a'..'f')
166
203
 
167
204
  def dialog(opts={}, &block)
168
205
  role :dialog, opts, &block
@@ -187,7 +224,7 @@ module RBMobile
187
224
  #
188
225
  # Additional properties that could be set:
189
226
  #
190
- # [theme] Change mobile theme ('a'..'f')
227
+ # [:theme] Change mobile theme ('a'..'f')
191
228
 
192
229
  def navbar(opts={}, &block)
193
230
  role :navbar, opts do
@@ -214,9 +251,9 @@ module RBMobile
214
251
  #
215
252
  # Additional properties that could be set:
216
253
  #
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
254
+ # [:theme] Change mobile theme ('a'..'f')
255
+ # [:icon] Icon to use, eg. 'delete' (refer to jquery mobile icon names)
256
+ # [:active] This will make current navigation item active
220
257
  #
221
258
  def navigate_to(url, label, opts={})
222
259
  options = {
@@ -246,9 +283,9 @@ module RBMobile
246
283
  #
247
284
  # Additional properties that could be set:
248
285
  #
249
- # [theme] Change mobile theme ('a'..'f')
250
- # [uibar] Include padding on the bar
251
- # [fixed] Fixed toolbars will re-appear after you scroll
286
+ # [:theme] Change mobile theme ('a'..'f')
287
+ # [:uibar] Include padding on the bar
288
+ # [:fixed] Fixed toolbars will re-appear after you scroll
252
289
 
253
290
  def footer(opts={}, &block)
254
291
  opts.merge!(:class => "ui-bar") if opts.delete(:uibar)
@@ -299,8 +336,8 @@ module RBMobile
299
336
  # [kind] Define icon used for button
300
337
  # [url] Where to move after click
301
338
  # [label] Text displayed in button
302
- # [theme] Change mobile theme ('a'..'f')
303
- # [ajax] Overide default AJAX setting
339
+ # [:theme] Change mobile theme ('a'..'f')
340
+ # [:ajax] Overide default AJAX setting
304
341
 
305
342
  def button(kind, url, label, opts={})
306
343
  options = {
@@ -384,7 +421,8 @@ module RBMobile
384
421
  # <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
422
  # </div>
386
423
  #
387
- # [collapsed] Determine whenever this block is collapsed or not
424
+ # [title] Give title to collapsable block
425
+ # [:collapsed] Determine whenever this block is collapsed or not
388
426
  #
389
427
  def collapse(title, opts={}, &block)
390
428
  opts[:'data-collapsed'] = 'true' if opts.delete(:collapsed) or @collapsed
@@ -411,6 +449,10 @@ module RBMobile
411
449
  # - collapse 'This is collapsible' do
412
450
  # Hello world!
413
451
  #
452
+ # Attributes:
453
+ #
454
+ # [:theme] Change default theme
455
+ #
414
456
  def collapse_set(opts={}, &block)
415
457
  @collapsed = true
416
458
  role :'collapsible-set', opts do
@@ -434,7 +476,8 @@ module RBMobile
434
476
  # Hello World!
435
477
  # = counter('3')
436
478
  #
437
- # [filter] Determine if search filter will show up or not
479
+ # [:filter] Determine if search filter will show up or not
480
+ # [:ordered] Create ordered list instead of unordered (Use 'ordered_list' method for this)
438
481
  #
439
482
  def list(opts={}, &block)
440
483
  opts[:element] = opts.delete(:ordered) ? :ol : :ul
@@ -449,6 +492,10 @@ module RBMobile
449
492
  # Same as 'list' but instead of creating a unorder list will create an
450
493
  # ordered list
451
494
  #
495
+ # Options:
496
+ #
497
+ # See 'list' method
498
+ #
452
499
  def ordered_list(opts={}, &block)
453
500
  list(opts.merge(:ordered => true), &block)
454
501
  end
@@ -459,9 +506,9 @@ module RBMobile
459
506
  #
460
507
  # Options:
461
508
  #
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
509
+ # [:icon] Define the right icon in list
510
+ # [:theme] Change default theme for single list item
511
+ # [:item_icon_url] Allow to display custom (64x64) icon on the left side
465
512
  #
466
513
  def item(opts={}, &block)
467
514
  opts[:'data-icon'] = opts.delete(:icon) if opts[:icon]
@@ -480,6 +527,10 @@ module RBMobile
480
527
  # - link 'a.html', :icon => 'alert' do
481
528
  # This item will send you to a.html
482
529
  #
530
+ # Options:
531
+ #
532
+ # See 'item' method
533
+ #
483
534
  def link(url, opts={}, &block)
484
535
  original_block = block
485
536
  new_block = Proc::new do
@@ -500,6 +551,10 @@ module RBMobile
500
551
  # - nested_item 'This is item header', :theme => 'b' do
501
552
  # This is item content
502
553
  #
554
+ # Options:
555
+ #
556
+ # See 'item' method
557
+ #
503
558
  def nested_item(title, opts={}, &block)
504
559
  original_block = block
505
560
  new_block = Proc::new do
@@ -551,6 +606,10 @@ module RBMobile
551
606
  # - item do
552
607
  # Andreas Muller
553
608
  #
609
+ # Options:
610
+ #
611
+ # [:theme] Change default theme for divider (broken in jquery.mobile 1.0b2)
612
+ #
554
613
  def divider(title, opts={})
555
614
  opts[:element] = :li
556
615
  capture_haml do
@@ -560,6 +619,22 @@ module RBMobile
560
619
  end
561
620
  end
562
621
 
622
+ # Wrapper for all HTML forms
623
+ #
624
+ # Example:
625
+ #
626
+ # - form '/save', :post do
627
+ # = input :name, :text, 'Name'
628
+ # = textarea :text
629
+ # = search_input :city, 'City'
630
+ # = toogle :switch, 'Switch'
631
+ #
632
+ # Options:
633
+ #
634
+ # [url] URL that handle the form data processing on the server
635
+ # [method] HTTP method to use (Default: POST)
636
+ # [:ajax] Overide default AJAX setting for this form
637
+ #
563
638
  def form(url, method=:post, opts={}, &block)
564
639
  opts.merge!(
565
640
  :method => method,
@@ -571,6 +646,31 @@ module RBMobile
571
646
  end
572
647
  end
573
648
 
649
+ # Text inputs and textareas are coded with standard HTML elements, then
650
+ # enhanced by jQuery Mobile to make them more attractive and useable on a
651
+ # mobile.
652
+ #
653
+ # Example:
654
+ #
655
+ # - form '/save' do
656
+ # = input :name, :text, 'Name'
657
+ # = input :surname, :text, 'Name', :required => true
658
+ #
659
+ # Options:
660
+ #
661
+ # [name] Element name
662
+ # [kind] Element type (:text, :radio, :checkbox, ...)
663
+ # [label] Element label (if nil, it will use 'name' as label)
664
+ # [:value] Default value for this input box
665
+ # [:placeholder] As soon as you click on (or tab to) the input field, the placeholder text disappears (HTML5)
666
+ # [:required] Mark this input as required (HTML5)
667
+ # [:patter] Validate value using regular expression (HTML5)
668
+ # [:min] Minimal value
669
+ # [:max] Maximum value
670
+ # [:maxlength] Maximum string length
671
+ # [:checked] Mark this input as 'checked' (used in :checkbox os :radio 'kind')
672
+ # [:no_complete] Disable autocompletetion
673
+ #
574
674
  def input(name, kind, label=nil, opts={})
575
675
  capture_haml do
576
676
  form_field do
@@ -587,12 +687,67 @@ module RBMobile
587
687
  end
588
688
  end
589
689
 
690
+ # Search inputs are a new HTML type that is styled with pill-shaped corners
691
+ # and adds a "x" icon to clear the field once you start typing.
692
+ #
693
+ # Example:
694
+ #
695
+ # - form 'save' do
696
+ # = search_input :city, 'City'
697
+ #
698
+ # Options:
699
+ #
700
+ # [name] Element name
701
+ #
702
+ # For more options see 'input' method.
703
+ #
590
704
  def search_input(name, label=nil, opts={})
591
705
  input(name, :search, label, {
592
706
  :'data-type' => :search,
593
707
  }.merge(opts))
594
708
  end
595
709
 
710
+ # To add a slider widget to your page, start with an input with a new HTML5
711
+ # type="range" attribute. Specify the value (current value), min and max
712
+ # attribute values to configure the slider.
713
+ #
714
+ # Example:
715
+ #
716
+ # - form '/save' do
717
+ # = slider :cash, 0, 100, 'How much?'
718
+ #
719
+ # Options:
720
+ #
721
+ # [name] Element name
722
+ # [min] Starting value
723
+ # [max] Maximum value
724
+ # [label] Element label
725
+ # [:value] Current value
726
+ #
727
+ # For other options see 'input' method
728
+ #
729
+ def slider(name, min, max, label=nil, opts={})
730
+ input(name, :range, label, {
731
+ :min => min,
732
+ :max => max
733
+ }.merge(opts))
734
+ end
735
+
736
+ # A binary "flip" switch is a common UI element on mobile devices that is
737
+ # used for any binary on/off or true/false type of data input. You can
738
+ # either drag the flip handle like a slider or tap on each half of the
739
+ # switch.
740
+ #
741
+ # Example:
742
+ #
743
+ # - form '/save' do
744
+ # = toogle :question, 'Be or not to be?'
745
+ #
746
+ # Options:
747
+ #
748
+ # [:first] Replace default 'on' with custom text
749
+ # [:second] Replace default 'off' with custom text
750
+ #
596
751
  def toogle(name, label=nil, opts={})
597
752
  capture_haml do
598
753
  form_field do
@@ -611,6 +766,25 @@ module RBMobile
611
766
  end
612
767
  end
613
768
 
769
+ # The select menus are driven off native select elements, but the native
770
+ # selects are hidden from view and replaced with a custom-styled select
771
+ # button that matches the look and feel of the jQuery Mobile framework. The
772
+ # replacement selects are ARIA-enabled and are keyboard accessible on the
773
+ # desktop as well.
774
+ #
775
+ # Example:
776
+ #
777
+ # - form '/save' do
778
+ # = select :pet, 'Select pet', ['Choose Pet', ['dog', 'Dog'], ['cat', 'Cat'], ['hamster', 'Hamster']]
779
+ #
780
+ # [name] Element name
781
+ # [label] Element label
782
+ # [options] Array with select options. This array should contain two
783
+ # dimensional array with 'value' and 'name'. If array item is a string
784
+ # instead of array it's used as select placeholder
785
+ # [:native] Enable native elements (don't use jquery.mobile UI)
786
+ # [:theme] Change theme for this select
787
+ #
614
788
  def select(name, label=nil, options=[], opts={})
615
789
  opts = {
616
790
  :'data-native-menu' => opts.delete(:native) ? 'true' : 'false',
@@ -634,6 +808,25 @@ module RBMobile
634
808
  end
635
809
  end
636
810
 
811
+ # Radio buttons are used to provide a list of options where only a single
812
+ # items can be selected. Traditional desktop radio buttons are not optimized
813
+ # for touch input so in jQuery Mobile, we style the label for the radio
814
+ # buttons so they are larger and look clickable. A custom set of icons are
815
+ # added to the label to provide additional visual feedback.
816
+ #
817
+ # Example:
818
+ #
819
+ # - form '/save' do
820
+ # = radio :pet, 'Choose pet vertical', ['cat', :dog, 'hamster', 'honey badger']
821
+ # = radio :pet, 'Choose pet', ['cat', :dog, 'hamster', 'honey badger'], :type => :horizontal
822
+ #
823
+ # Options:
824
+ #
825
+ # [name] Element name
826
+ # [label] Element label
827
+ # [options] List of possible options. Use 'Symbol' instead of 'String' if you want to make some value 'checked'
828
+ # [:type] You can have 'horizontal' or 'vertical' radio group (Default: vertical)
829
+ #
637
830
  def radio(name, label=nil, options=[], opts={})
638
831
  capture_haml do
639
832
  form_field do
@@ -653,6 +846,31 @@ module RBMobile
653
846
  end
654
847
  end
655
848
 
849
+ # Checkboxes are used to provide a list of options where more than one can
850
+ # be selected. Traditional desktop checkboxes are not optimized for touch
851
+ # input so in jQuery Mobile, we style the label for the checkboxes so they
852
+ # are larger and look clickable. A custom set of icons are added to the
853
+ # label to provide additional visual feedback.
854
+
855
+ # Both the radio and checkbox controls below use standard input/label
856
+ # markup, but are styled to be more touch-friendly. The styled control you
857
+ # see is actually the label element, which sits over the real input, so if
858
+ # images fail to load, you'll still have a functional control. In most
859
+ # browsers, clicking the label automatically triggers a click on the input,
860
+ # but we've had to trigger the update manually for a few mobile browsers
861
+ # that don't do this natively. On the desktop, these controls are keyboard
862
+ # and screen-reader accessible.
863
+ #
864
+ # Examples:
865
+ #
866
+ # - form do
867
+ # = checkbox :pet, 'Choose multiple pets', ['cat', :dog, 'hamster', 'honey badger']
868
+ # = checkbox :pet, 'Choose multiple pets horizontal', ['cat', :dog, 'hamster', 'honey badger'], :type => :horizontal
869
+ #
870
+ # Options:
871
+ #
872
+ # See 'radio' method.
873
+ #
656
874
  def checkbox(name, label=nil, options=[], opts={})
657
875
  capture_haml do
658
876
  form_field do
@@ -672,6 +890,26 @@ module RBMobile
672
890
  end
673
891
  end
674
892
 
893
+ # For multi-line text inputs, use a textarea element. The framework will
894
+ # auto-grow the height of the textarea to avoid the need for an internal
895
+ # scrollbar which is very hard to use on a mobile device.
896
+ #
897
+ # Examples:
898
+ #
899
+ # - form do
900
+ # = textarea :text
901
+ #
902
+ # Options:
903
+ #
904
+ # [name] Element name
905
+ # [label] Element label
906
+ # [:cols] Number of columns
907
+ # [:rows] Number of rows
908
+ # [:placeholder] See 'input'
909
+ # [:required] Make textarea required (HTML5)
910
+ # [:content] Insert some content into textarea
911
+ # [:maxlength] Maximum text length (HTML5)
912
+ #
675
913
  def textarea(name, label=nil, opts={})
676
914
  capture_haml do
677
915
  form_field do
@@ -687,10 +925,28 @@ module RBMobile
687
925
  end
688
926
  end
689
927
 
928
+ # Basic wrapper for all form fields
929
+ #
930
+ # Options:
931
+ #
932
+ # [:theme] Change default theme
933
+ #
690
934
  def form_field(opts={}, &block)
691
935
  role :'fieldcontain', opts, &block
692
936
  end
693
937
 
938
+ # Form submitter
939
+ #
940
+ # Example:
941
+ #
942
+ # - form do
943
+ # = submit 'Submit this form'
944
+ #
945
+ # Options:
946
+ #
947
+ # [label] Text displayed in button (Default: 'Submit')
948
+ # [:theme] Change the default theme for button
949
+ #
694
950
  def submit(label=nil, opts={})
695
951
  opts = {
696
952
  :'data-theme' => opts.delete(:theme)
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbmobile
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
9
+ version: "1.0"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Michal Fojtik