jqm_helper 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ # gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2.2)
10
+ rcov (0.9.11)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.0.0)
17
+ jeweler (~> 1.6.4)
18
+ rcov
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2011 Peter Ehrlich
2
+
3
+ tl;dr: DIY!
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ = jqm_helper
2
+
3
+ **ALPHA**
4
+
5
+ A quick and dirty, but functional, collection of tools for speeding up development with jquery mobile.
6
+
7
+ Enforces a number of sensible defaults, reducing iritable bugs.
8
+
9
+ Includes view helpers and will soon include some handy javascript tools (such as for handling json data).
10
+
11
+
12
+ ## Install
13
+
14
+ gem install streama
15
+
16
+
17
+ ## Usage
18
+
19
+ ### buttons
20
+
21
+ ```ruby
22
+ jqm_button 'Open Refridgerator', open_fridge_path
23
+ # <a data-role="button" data-prefetch="true" href="/fridge/open">
24
+
25
+ back_button
26
+ # <a data-role="button" data-prefetch="true" data-rel="back" >
27
+
28
+ backwards_button('Close Refridgerator', close_fridge_path, {class: 'sears'})
29
+ # <a data-role="button" data-prefetch="true" href="/fridge/close" class="sears"
30
+ data-icon="arrow-l" data-direction="reverse">
31
+
32
+ forwards_button('Make Sandwitch', sandwitch_path, {data: {prefetch: false} })
33
+ # <a data-role="button" href="/sandwitch/make"
34
+ data-icon="arrow-r" data-iconpos="right">
35
+
36
+ # and even:
37
+ dialog_button 'rm -fr /', '/doom'
38
+ # <a data-role="button" data-prefetch="true" href="/doom"
39
+ data-rel="dialog" data-transition="slidedown">
40
+ ```
41
+
42
+ Every method has optional arguments. They can overwrite the sensible defaults.
43
+
44
+ A very cool syntax can be used:
45
+
46
+ ```ruby
47
+ { data: { icon: 'star', prefetch: false } }
48
+ # typing that beats the pants off these keyboard gymnastics:
49
+ # { :'data-icon' => 'star, :'data-prefetch' => false }
50
+ ```
51
+
52
+ ### slider tag
53
+
54
+ ```ruby
55
+ def slider_tag(name, label)
56
+ raw %Q{
57
+ <div data-role="fieldcontain" style="border: 0; margin: 0; padding: 1em 0 0 0;">
58
+ <label style="" for="#{name}">#{label}</label>
59
+ <select name="#{name}" id="#{name}" data-role="slider">
60
+ <option value="no">Off</option>
61
+ <option value="yes">On</option>
62
+ </select>
63
+ </div>
64
+ }
65
+ end
66
+ ```
67
+
68
+ This could be made more flexible
69
+
70
+ ### page builder
71
+
72
+ ```ruby
73
+ jqm_page 'discovery' do
74
+ # it generates:
75
+ # <div class="discovery_page" data-role="page" data-title="Discovery" id="discovery_page">
76
+ # <meta content="authenticity_token" name="csrf-param">
77
+ # <meta content="Oegb/DVSrtDYKJNdXtjQo63eGCBUwtpW83Bysz8h/nQ=" name="csrf-token">
78
+ ```
79
+
80
+
81
+ ### nav builder
82
+
83
+ - Adds class to active page
84
+ - Reverses animation direction as appropriate (very handy)
85
+
86
+ ```ruby
87
+ nav_for :discover do |n| # discover will be the active button
88
+ # any buttons before it will display the reverse animation, any after will be forwards
89
+ n.button('discover',
90
+ {
91
+ :href => discover_path,
92
+ :data =>{
93
+ :icon => :search,
94
+ }
95
+ })
96
+ end
97
+
98
+ # <div data-role="controlgroup" data-type="horizontal" class="ui-corner-all ui-controlgroup ui-controlgroup-horizontal">
99
+ # <a class="ui-btn-active" data-icon="search" data-prefetch="true" data-role="button" href="/discover">
100
+ # Discover
101
+ # </a>
102
+ # </div>
103
+ ```
104
+
105
+
106
+ = Contributing
107
+
108
+
109
+ Once you've made your great commits
110
+
111
+ 1. Fork
112
+ 1. Create a topic branch - git checkout -b my_branch
113
+ 1. Push to your branch - git push origin my_branch
114
+ 1. Create a Pull Request from your branch
115
+ 1. That's it!
116
+
117
+
118
+
119
+ = Contributors
120
+
121
+ Peter Ehrlich [http://www.twitter.com/ehrlicp](@ehrlicp)
122
+
123
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ # https://github.com/technicalpickles/jeweler
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+ require 'rake'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "jqm_helper"
19
+ gem.homepage = "http://github.com/pehrlich/jqm_helper"
20
+ gem.license = "MIT"
21
+ gem.summary = %q{big conveniences for jquery mobile}
22
+ gem.description = %Q{helper methods for generating markup, soon: javascript helpers}
23
+ gem.email = "peter.i.ehrlich@gmail.com"
24
+ gem.authors = ["Peter Ehrlich"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "jqm_helper #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "jqm_helper"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Peter Ehrlich"]
12
+ s.date = "2011-12-22"
13
+ s.description = "helper methods for generating markup, soon: javascript helpers"
14
+ s.email = "peter.i.ehrlich@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "jqm_helper.gemspec",
28
+ "lib/jqm_helper.rb",
29
+ "lib/jqm_helper/nav_builder.rb",
30
+ "lib/jqm_helper/railtie.rb",
31
+ "lib/jqm_helper/tag_helpers.rb",
32
+ "test/helper.rb",
33
+ "test/test_jqm_helper.rb"
34
+ ]
35
+ s.homepage = "http://github.com/pehrlich/jqm_helper"
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "1.8.13"
39
+ s.summary = "big conveniences for jquery mobile"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
51
+ s.add_dependency(%q<rcov>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
56
+ s.add_dependency(%q<rcov>, [">= 0"])
57
+ end
58
+ end
59
+
@@ -0,0 +1,52 @@
1
+ module JqmHelper
2
+
3
+ def nav_for(page, &block) # someday: options
4
+ builder = NavBuilder.new(page)
5
+ content_tag :div, capture(builder, &block), make_options({data: {role: 'controlgroup', type: 'horizontal'}}, {})
6
+ end
7
+
8
+
9
+ class NavBuilder
10
+ include JqmHelper # heh.. this is not circular.. how?
11
+ # someday: why don't these get included by including JqmHelper
12
+ include ActionView::Helpers::OutputSafetyHelper # raw include ActionView::Helpers::OutputSafetyHelper # raw
13
+ include ActionView::Helpers::TagHelper # content_tag
14
+
15
+ #include ActionView::Helpers::UrlHelper
16
+ #include ActionDispatch::Routing
17
+ # lib/jqm_helper.rb:23:in `<module:JqmHelper>': undefined method `routes' for nil:NilClass (NoMethodError)
18
+ #include Rails.application.routes.url_helpers
19
+
20
+
21
+ ACTIVE_CLASS = 'ui-btn-active'
22
+ cattr_accessor :reverse_animation_direction
23
+
24
+ def initialize(active_action = '')
25
+ self.reverse_animation_direction = true
26
+ @active_action = active_action.to_s
27
+ # someday: we may be able to replace with rails current_page helper
28
+ end
29
+
30
+ def button(action, options, title = nil)
31
+
32
+ if active = action.to_s == @active_action
33
+ self.reverse_animation_direction = false
34
+ end
35
+
36
+ defaults = {
37
+ :class => active ? ACTIVE_CLASS : '',
38
+ :data => {
39
+ :icon => action,
40
+ }
41
+ }
42
+
43
+ # commented from trouble including named routes =/
44
+ #defaults[:href] = method("#{action}_path").call unless options[:href] # incase method 404
45
+
46
+ defaults[:data][:direction] = 'reverse' if self.reverse_animation_direction
47
+
48
+ jqm_button(title || action.capitalize, '', make_options(defaults, options))
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,8 @@
1
+ module JqmHelper
2
+ class Railtie < Rails::Railtie
3
+ ActiveSupport.on_load(:action_view) do
4
+ include JqmHelper
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,122 @@
1
+ module JqmHelper
2
+
3
+ def jqm_page(title, options = {}, &block)
4
+ defaults = {
5
+ :class => "#{title.downcase}_page",
6
+ :id => "#{title.downcase}_page",
7
+ :data => {
8
+ :role => 'page',
9
+ :title => title.capitalize,
10
+ }
11
+ }
12
+
13
+ script = ''
14
+
15
+ #session.delete('load_resource') { [] }.each do |name, resource|
16
+ # o = {}
17
+ # logger.warn "loading resource: #{name}, #{resource.last}. #{resource.first}"
18
+ # o[name] = resource.first.where({_id: resource.last})
19
+ # script << "window.load_resource(#{resource.to_json}');\n"
20
+ #end
21
+
22
+ # todo: assets version gemified
23
+ content_tag(:div, raw(%Q{
24
+ <meta name="assets_version" content="#{1 || Brickbook::Application.config.assets.version}"/>
25
+ #{csrf_meta_tags}
26
+ <!--<script type='text/javascript'>#{script}</script>-->
27
+ #{capture(&block)}
28
+ }), make_options(defaults, options))
29
+ end
30
+
31
+ #def jqm_list(collection, options, &block)
32
+ # defaults ={
33
+ # data: {
34
+ # role: :listview
35
+ # }
36
+ # }
37
+ # contents = ''
38
+ # collection.each do |item|
39
+ # contents << capture( &block )
40
+ # end
41
+ # out = content_tag(:div, contents, make_options(defaults, options))
42
+ #end
43
+
44
+
45
+ def jqm_button(text, href_or_options, options = {})
46
+ defaults = {
47
+ data: {
48
+ role: :button,
49
+ prefetch: :true
50
+ }
51
+ }
52
+ if href_or_options.is_a? Hash
53
+ options = href_of_options
54
+ else
55
+ # we allow href to be overridden by options. Convenient or a pain?
56
+ defaults[:href] = href_or_options
57
+ end
58
+
59
+ defaults[:class] = 'notext' if text.blank? || text=='&nbsp;'
60
+
61
+ content_tag(:a, raw(text), make_options(defaults, options))
62
+ end
63
+
64
+ def dialog_button(text, href, options = {})
65
+ defaults = {
66
+ data: {
67
+ rel: :dialog,
68
+ transition: :slidedown,
69
+ }
70
+ }
71
+ jqm_button(text, href, make_options(defaults, options))
72
+ end
73
+
74
+ def forward_button(text, href, options = {})
75
+ defaults = {
76
+ :href => href,
77
+ :data => {
78
+ :role => :button,
79
+ :icon => 'arrow-r',
80
+ :iconpos => 'right'
81
+ }
82
+ }
83
+
84
+ content_tag(:a, raw(text), make_options(defaults, options))
85
+ end
86
+ alias_method :forwards_button, :forward_button
87
+
88
+ def backward_button(text, href, options = {})
89
+ defaults = {
90
+ :href => href,
91
+ :data => {
92
+ :role => :button,
93
+ :icon => 'arrow-l',
94
+ :direction => 'reverse'
95
+ }
96
+ }
97
+
98
+ content_tag(:a, raw(text), make_options(defaults, options))
99
+ end
100
+ alias_method :backwards_button, :backward_button
101
+
102
+ def back_button(options = {})
103
+ defaults = {
104
+ data: {
105
+ rel: :back
106
+ }
107
+ }
108
+ backwards_button('Back', '#', make_options(defaults, options))
109
+ end
110
+
111
+ def slider_tag(name, label)
112
+ raw %Q{
113
+ <div data-role="fieldcontain" style="border: 0; margin: 0; padding: 1em 0 0 0;">
114
+ <label style="" for="#{name}">#{label}</label>
115
+ <select name="#{name}" id="#{name}" data-role="slider">
116
+ <option value="no">Off</option>
117
+ <option value="yes">On</option>
118
+ </select>
119
+ </div>
120
+ }
121
+ end
122
+ end
data/lib/jqm_helper.rb ADDED
@@ -0,0 +1,39 @@
1
+ # automatically reload on each request: (and add to application_controller)
2
+ #require_dependency 'jqm_helper/railtie' if defined?(Rails)
3
+ #require_dependency 'jqm_helper/tag_helpers' if defined?(Rails)
4
+ #require_dependency 'jqm_helper/nav_builder' if defined?(Rails)
5
+
6
+ require 'jqm_helper/railtie' if defined?(Rails)
7
+ require 'jqm_helper/tag_helpers' if defined?(Rails)
8
+ require 'jqm_helper/nav_builder' if defined?(Rails)
9
+
10
+
11
+
12
+ module JqmHelper
13
+ include ActionView::Helpers::OutputSafetyHelper # raw
14
+ include ActionView::Helpers::TagHelper # content_tag
15
+
16
+ def make_options(defaults, custom)
17
+
18
+ [defaults, custom].each do |options|
19
+ # standardize keys:
20
+ if data = options.delete(:data)
21
+ data.each do |k, v|
22
+ options[:"data-#{k}"] = v
23
+ end
24
+ end
25
+ end
26
+
27
+ options = defaults.merge(custom)
28
+ options.delete(:'data-prefetch') if options[:'data-prefetch'] == false
29
+ options
30
+ end
31
+
32
+ end
33
+
34
+
35
+ # doc:
36
+ # https://github.com/justinfrench/formtastic/tree/master/lib/formtastic
37
+ # http://edgeapi.rubyonrails.org/classes/Rails/Railtie.html
38
+ # http://www.igvita.com/2010/08/04/rails-3-internals-railtie-creating-plugins/
39
+ # http://www.engineyard.com/blog/2010/extending-rails-3-with-railties/
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'jqm_helper'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestJqmHelper < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jqm_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Peter Ehrlich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70189261795260 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70189261795260
25
+ - !ruby/object:Gem::Dependency
26
+ name: jeweler
27
+ requirement: &70189261794020 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.4
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70189261794020
36
+ - !ruby/object:Gem::Dependency
37
+ name: rcov
38
+ requirement: &70189261792320 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70189261792320
47
+ description: ! 'helper methods for generating markup, soon: javascript helpers'
48
+ email: peter.i.ehrlich@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - LICENSE.txt
53
+ - README.md
54
+ files:
55
+ - .document
56
+ - Gemfile
57
+ - Gemfile.lock
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - VERSION
62
+ - jqm_helper.gemspec
63
+ - lib/jqm_helper.rb
64
+ - lib/jqm_helper/nav_builder.rb
65
+ - lib/jqm_helper/railtie.rb
66
+ - lib/jqm_helper/tag_helpers.rb
67
+ - test/helper.rb
68
+ - test/test_jqm_helper.rb
69
+ homepage: http://github.com/pehrlich/jqm_helper
70
+ licenses:
71
+ - MIT
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ segments:
83
+ - 0
84
+ hash: -3746104091147986666
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.13
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: big conveniences for jquery mobile
97
+ test_files: []