rbmobile 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +61 -10
- data/Rakefile +23 -0
- data/lib/mobile_helpers.rb +144 -0
- data/tests/basic_test.rb +86 -0
- metadata +6 -4
data/README.markdown
CHANGED
@@ -1,29 +1,78 @@
|
|
1
|
-
# Ruby
|
1
|
+
# Ruby jquery.mobile
|
2
2
|
|
3
|
-
A swiss knife for creating a hipster
|
3
|
+
A swiss knife for creating a hipster rich user-interfaces supposed to looks great on mobile devices.
|
4
4
|
|
5
5
|
### Description
|
6
6
|
|
7
7
|
This project should help you to create more readable HAML templates for your
|
8
|
-
mobile
|
9
|
-
|
8
|
+
mobile application using http://jquerymobile.com framework.
|
9
|
+
|
10
|
+
### Example
|
11
|
+
|
12
|
+
Save your fingers! and write this code:
|
13
|
+
|
14
|
+
- page :theme => 'c' do
|
15
|
+
- header do
|
16
|
+
%h1 Page header
|
17
|
+
- content do
|
18
|
+
- list do
|
19
|
+
= divider "Awesome list"
|
20
|
+
- item do
|
21
|
+
Awesome list item
|
22
|
+
- footer do
|
23
|
+
- navbar do
|
24
|
+
- navigate_to 'a.html', 'Awesome', :icon => 'load'
|
25
|
+
- navigate_to 'b.html', 'Yeah!', :icon => 'save'
|
26
|
+
|
27
|
+
Instead of this code:
|
28
|
+
|
29
|
+
%div{ :'data-role' => 'page', :'data-theme' => 'c'}
|
30
|
+
%div{ :'data-role' => 'header'}
|
31
|
+
%h1 Page header
|
32
|
+
%div{ :'data-role' => 'content'}
|
33
|
+
%ul{ :'data-role' => 'list-view'}
|
34
|
+
%li{ :'data-role' => 'listdivider'} Awesome list
|
35
|
+
%li Awesome list item
|
36
|
+
%div{ :'data-role' => 'footer' }
|
37
|
+
%div{ :'data-role' => 'navbar'}
|
38
|
+
%ul
|
39
|
+
%li
|
40
|
+
%a{ :href => 'a.html', :'data-icon' => :save } Awesome
|
41
|
+
%a{ :href => 'a.html', :'data-icon' => :save } Awesome
|
42
|
+
|
43
|
+
And there is even more magic and autogenerator inside!
|
10
44
|
|
11
45
|
### Documentation
|
12
46
|
|
13
|
-
|
47
|
+
|
48
|
+
- RDoc: http://rdoc.info/projects/mfojtik/rbmobile
|
49
|
+
- JQuery.Mobile: http://jquerymobile.com
|
14
50
|
|
15
51
|
### Requirements
|
16
52
|
|
17
53
|
- You should include JQuery library in your project or place this library into
|
18
|
-
'public' folder
|
54
|
+
'public' folder (it should be accessible in /jquery-xxx.min.js)
|
55
|
+
|
19
56
|
- You should unzip JQuery mobile inside your 'public' folder:
|
20
57
|
|
21
|
-
$ wget http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.zip
|
58
|
+
$ wget http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.zip \
|
59
|
+
-O public/jquery.mobile-1.0b2.zip
|
22
60
|
$ cd public && unzip jquery.mobile-1.0b2.zip
|
61
|
+
|
62
|
+
- JQuery.mobile folder should be accessible in /jquery.mobile-xxx/
|
63
|
+
|
23
64
|
|
24
65
|
### Installation
|
25
66
|
|
26
67
|
gem install rbmobile
|
68
|
+
|
69
|
+
### Demo app
|
70
|
+
|
71
|
+
$ git clone git://github.com/mifo/rbmobile.git
|
72
|
+
$ gem install sinatra sinatra-respond_to
|
73
|
+
$ cd rbmobile/example
|
74
|
+
$ ruby app.rb
|
75
|
+
$ open http://localhost:4567/
|
27
76
|
|
28
77
|
### Sinatra
|
29
78
|
|
@@ -32,15 +81,17 @@ http://rdoc.info/projects/mfojtik/rbmobile
|
|
32
81
|
|
33
82
|
### Rails(?)
|
34
83
|
|
35
|
-
|
84
|
+
app/helpers/application_helper.rb:
|
85
|
+
|
36
86
|
require 'mobile_helpers'
|
37
87
|
include RBMobile::Helpers
|
38
88
|
|
39
89
|
### TODO:
|
40
90
|
|
41
|
-
- Finish forms
|
91
|
+
- Finish with jquery.mobile forms
|
92
|
+
- Make public directory configurable
|
42
93
|
|
43
|
-
|
94
|
+
### LICENSE:
|
44
95
|
|
45
96
|
Copyright (c) 20011 Michal Fojtik
|
46
97
|
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'rcov/rcovtask'
|
3
|
+
|
4
|
+
task :default_rcov_params_for_units do
|
5
|
+
RCOV_PARAMS = ENV['RCOV_PARAMS'] = "--sort=coverage"
|
6
|
+
SHOW_ONLY = ENV['SHOW_ONLY'] = "lib/mobile_helpers.rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
task :default_rcov do
|
10
|
+
puts "Executing rcov..."
|
11
|
+
FileUtils::rm_rf 'coverage'
|
12
|
+
command = "rcov --exclude 'Gems/*,gems/*' lib/*"
|
13
|
+
puts command
|
14
|
+
`#{command}`
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'RCov code coverage'
|
18
|
+
task :rcov => [ :default_rcov_params_for_units, :default_rcov ]
|
19
|
+
|
20
|
+
Rake::TestTask.new do |i|
|
21
|
+
i.test_files = FileList['tests/*_test.rb']
|
22
|
+
i.verbose = true
|
23
|
+
end
|
data/lib/mobile_helpers.rb
CHANGED
@@ -560,6 +560,150 @@ module RBMobile
|
|
560
560
|
end
|
561
561
|
end
|
562
562
|
|
563
|
+
def form(url, method=:post, opts={}, &block)
|
564
|
+
opts.merge!(
|
565
|
+
:method => method,
|
566
|
+
:url => url
|
567
|
+
)
|
568
|
+
opts.merge!(:'data-ajax' => 'false') if not RBMobile::config[:ajax] and not opts.delete(:ajax)
|
569
|
+
haml_tag :form, opts do
|
570
|
+
block.call if block_given?
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
def input(name, kind, label=nil, opts={})
|
575
|
+
capture_haml do
|
576
|
+
form_field do
|
577
|
+
haml_tag :label, :for => name do
|
578
|
+
haml_concat label || name.to_s.capitalize
|
579
|
+
end
|
580
|
+
haml_tag :input, { :name => name, :id => name, :type => kind, :value => opts.delete(:value),
|
581
|
+
:placeholder => opts.delete(:placeholder), :required => opts.delete(:required) ? 'required' : nil,
|
582
|
+
:pattern => opts.delete(:pattern), :min => opts.delete(:min), :max => opts.delete(:max),
|
583
|
+
:maxlength => opts.delete(:maxlength) || opts.delete(:size), :checked => opts.delete(:checked) ? 'checked' : nil,
|
584
|
+
:autocomplete => opts.delete(:no_complete) ? 'off' : nil }.merge(opts)
|
585
|
+
|
586
|
+
end
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
590
|
+
def search_input(name, label=nil, opts={})
|
591
|
+
input(name, :search, label, {
|
592
|
+
:'data-type' => :search,
|
593
|
+
}.merge(opts))
|
594
|
+
end
|
595
|
+
|
596
|
+
def toogle(name, label=nil, opts={})
|
597
|
+
capture_haml do
|
598
|
+
form_field do
|
599
|
+
haml_tag :label, :for => name do
|
600
|
+
haml_concat label || name.to_s.capitalize
|
601
|
+
end
|
602
|
+
haml_tag :select, :id => name, :'data-role' => 'slider' do
|
603
|
+
haml_tag :option, :value => opts[:first] || 'on' do
|
604
|
+
haml_concat opts[:first] ? opts[:first].to_s.capitalize : 'On'
|
605
|
+
end
|
606
|
+
haml_tag :option, :value => opts[:second] || 'off' do
|
607
|
+
haml_concat opts[:second] ? opts[:second].to_s.capitalize : 'Off'
|
608
|
+
end
|
609
|
+
end
|
610
|
+
end
|
611
|
+
end
|
612
|
+
end
|
613
|
+
|
614
|
+
def select(name, label=nil, options=[], opts={})
|
615
|
+
opts = {
|
616
|
+
:'data-native-menu' => opts.delete(:native) ? 'true' : 'false',
|
617
|
+
:'data-theme' => opts.delete(:theme)
|
618
|
+
}.merge(opts)
|
619
|
+
capture_haml do
|
620
|
+
form_field do
|
621
|
+
haml_tag :label, :for => name do
|
622
|
+
haml_concat label || name.to_s.capitalize
|
623
|
+
end
|
624
|
+
haml_tag :select, { :id => name }.merge(opts) do
|
625
|
+
options.each do |option|
|
626
|
+
option = [option] unless option.kind_of? Array
|
627
|
+
# One-item array will create a placeholder
|
628
|
+
haml_tag :option, :value => option.size==2 ? option.first : nil, :'data-placeholder' => option.size==1 ? 'true' : nil do
|
629
|
+
haml_concat option.last
|
630
|
+
end
|
631
|
+
end
|
632
|
+
end
|
633
|
+
end
|
634
|
+
end
|
635
|
+
end
|
636
|
+
|
637
|
+
def radio(name, label=nil, options=[], opts={})
|
638
|
+
capture_haml do
|
639
|
+
form_field do
|
640
|
+
haml_tag :fieldset, :'data-role' => :controlgroup, :'data-type' => opts[:type] || 'vertical' do
|
641
|
+
haml_tag :legend do
|
642
|
+
haml_concat label || name.to_s.capitalize
|
643
|
+
end
|
644
|
+
options.each_with_index do |option, index|
|
645
|
+
haml_tag :input, :name => name, :id => "#{name}-choice-#{index}", :type => :radio,
|
646
|
+
:value => option, :checked => option.kind_of?(Symbol) ? 'checked' : nil
|
647
|
+
haml_tag :label, :for => "#{name}-choice-#{index}" do
|
648
|
+
haml_concat option
|
649
|
+
end
|
650
|
+
end
|
651
|
+
end
|
652
|
+
end
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
def checkbox(name, label=nil, options=[], opts={})
|
657
|
+
capture_haml do
|
658
|
+
form_field do
|
659
|
+
haml_tag :fieldset, :'data-role' => :controlgroup, :'data-type' => opts[:type] || 'vertical' do
|
660
|
+
haml_tag :legend do
|
661
|
+
haml_concat label || name.to_s.capitalize
|
662
|
+
end
|
663
|
+
options.each_with_index do |option, index|
|
664
|
+
haml_tag :input, :name => "name[#{index}]", :id => "#{name}-choice-#{index}", :type => :checkbox,
|
665
|
+
:value => option, :checked => option.kind_of?(Symbol) ? 'checked' : nil
|
666
|
+
haml_tag :label, :for => "#{name}-choice-#{index}" do
|
667
|
+
haml_concat option
|
668
|
+
end
|
669
|
+
end
|
670
|
+
end
|
671
|
+
end
|
672
|
+
end
|
673
|
+
end
|
674
|
+
|
675
|
+
def textarea(name, label=nil, opts={})
|
676
|
+
capture_haml do
|
677
|
+
form_field do
|
678
|
+
haml_tag :label, :for => name do
|
679
|
+
haml_concat label || name.to_s.capitalize
|
680
|
+
end
|
681
|
+
haml_tag :'textarea', :'<', :name => name, :id => name, :cols => opts[:cols], :rows => opts[:rows],
|
682
|
+
:placeholder => opts[:placeholder], :required => opts[:required] ? 'required' : nil,
|
683
|
+
:maxlength => opts[:maxlength] do
|
684
|
+
haml_concat opts[:content] if opts[:content]
|
685
|
+
end
|
686
|
+
end
|
687
|
+
end
|
688
|
+
end
|
689
|
+
|
690
|
+
def form_field(opts={}, &block)
|
691
|
+
role :'fieldcontain', opts, &block
|
692
|
+
end
|
693
|
+
|
694
|
+
def submit(label=nil, opts={})
|
695
|
+
opts = {
|
696
|
+
:'data-theme' => opts.delete(:theme)
|
697
|
+
}.merge(opts)
|
698
|
+
capture_haml do
|
699
|
+
form_field do
|
700
|
+
haml_tag :button, { :type => :submit }.merge(opts), :value => label do
|
701
|
+
haml_concat label || 'Submit'
|
702
|
+
end
|
703
|
+
end
|
704
|
+
end
|
705
|
+
end
|
706
|
+
|
563
707
|
private
|
564
708
|
|
565
709
|
def role(name, opts={}, &block)
|
data/tests/basic_test.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'haml'
|
3
|
+
require 'lib/mobile_helpers'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
class TestRoles < MiniTest::Unit::TestCase
|
8
|
+
|
9
|
+
extend Haml
|
10
|
+
include Haml::Helpers
|
11
|
+
include RBMobile::Helpers
|
12
|
+
|
13
|
+
def setup
|
14
|
+
init_haml_helpers
|
15
|
+
RBMobile::config do
|
16
|
+
disable :ajax
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_it_generates_basic_page_role
|
21
|
+
output = capture_haml do
|
22
|
+
page
|
23
|
+
end
|
24
|
+
retval = Nokogiri::HTML(output)
|
25
|
+
assert_equal retval.css("div").size, 1
|
26
|
+
assert_nil retval.css("div").first[:class]
|
27
|
+
assert_equal retval.css("div").first[:'data-role'], 'page'
|
28
|
+
assert_empty retval.css("div *")
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_it_generates_themed_page_role
|
32
|
+
output = capture_haml do
|
33
|
+
page :theme => :c
|
34
|
+
end
|
35
|
+
retval = Nokogiri::HTML(output)
|
36
|
+
assert_equal retval.css("div").first[:'data-theme'], 'c'
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_it_generates_titled_page_role
|
40
|
+
output = capture_haml do
|
41
|
+
page :title => "Test1"
|
42
|
+
end
|
43
|
+
retval = Nokogiri::HTML(output)
|
44
|
+
assert_equal retval.css("div").first[:'data-title'], 'Test1'
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_it_generates_basic_header_role
|
48
|
+
output = capture_haml do
|
49
|
+
page do
|
50
|
+
header do
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
retval = Nokogiri::HTML(output)
|
55
|
+
assert_equal retval.css("div[@data-role=page] div").size, 1
|
56
|
+
assert_equal retval.css("div[@data-role=page] div").first[:'data-role'], "header"
|
57
|
+
assert_equal retval.css("div[@data-role=page] div").first[:'data-position'], "inline"
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_it_generates_basic_navbar_role
|
61
|
+
output = capture_haml do
|
62
|
+
page do
|
63
|
+
footer do
|
64
|
+
navbar do
|
65
|
+
haml_concat navigate_to "a.html", "Test"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
retval = Nokogiri::HTML(output)
|
71
|
+
assert_equal retval.css("div[@data-role=page] > div").size, 1
|
72
|
+
assert_equal retval.css("div[@data-role=page] div").first[:'data-role'], "footer"
|
73
|
+
assert_equal retval.css("div[@data-role=page] div[@data-role=footer] div").first[:'data-role'], "navbar"
|
74
|
+
assert_equal retval.css("div[@data-role=page] div[@data-role=footer] div").size, 1
|
75
|
+
assert_equal retval.css("div[@data-role=page] div[@data-role=footer] div ul").size, 1
|
76
|
+
assert_equal retval.css("div[@data-role=page] div[@data-role=footer] div ul li").size, 1
|
77
|
+
assert_equal retval.css("div[@data-role=page] div[@data-role=footer] div ul li a").size, 1
|
78
|
+
assert_equal retval.css("div[@data-role=page] div[@data-role=footer] div ul li a").first[:href], 'a.html'
|
79
|
+
assert_equal retval.css("div[@data-role=page] div[@data-role=footer] div ul li a").first.text.strip, 'Test'
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbmobile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michal Fojtik
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-17 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -42,6 +42,8 @@ extra_rdoc_files: []
|
|
42
42
|
|
43
43
|
files:
|
44
44
|
- lib/mobile_helpers.rb
|
45
|
+
- tests/basic_test.rb
|
46
|
+
- Rakefile
|
45
47
|
- README.markdown
|
46
48
|
has_rdoc: true
|
47
49
|
homepage: http://github.com/mifo/rbmobile
|