diff --git a/.gitignore b/.gitignore index 35e5213..b7ac234 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,20 @@ .bundle .rvmrc -*.gem \ No newline at end of file +*.gem +# rcov generated +coverage + +# rdoc generated +rdoc + +# yard generated +doc +.yardoc + +# bundler +.bundle + +# jeweler generated +pkg +.DS_Store + diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..7abe2a1 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color --format nested \ No newline at end of file diff --git a/CHANGELOG b/CHANGELOG index 41d730a..3bbfc3c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,19 @@ +== 03-19-2012 + + * Added support for Filamentgroup UI Select Slider with labels and tooltips + * Added vendor folder with Select Slider assets which should be added to Sprocket path + * select_ui_slider.js + * ui_slider.extras.css + == 01-24-2011 * rewrote for rails 3 && (ruby 1.8 || ruby 1.9), added tests +== 11-14-2010 + + * refactored for Rails 3 + * added Rspec tests + == 03-07-2009 * big change: removed the 2nd param for concat, rails no longer requires the binding be passed. @@ -17,4 +29,4 @@ == 06-22-2008 initial import - * TabsRenderer added \ No newline at end of file + * TabsRenderer added diff --git a/Gemfile b/Gemfile index c80ee36..9a60fcb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,17 @@ -source "http://rubygems.org" +source :rubygems + +# gemspec +gem "haml" + +# Add dependencies to develop your gem here. +# Include everything needed to run rake, tests, features, etc. +group :development do + gem "rails", ">= 3" + gem "rspec", ">= 2" + gem "rspec-rails", ">= 2.5" + gem "shoulda", ">= 0" + gem "bundler", ">= 1.0.0" + gem "jeweler", ">= 1.5.2" + gem "simplecov", ">= 0" +end -gemspec diff --git a/Gemfile.lock b/Gemfile.lock index bf0246b..4e52927 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,83 +1,122 @@ -PATH - remote: . - specs: - jquery_ui_rails_helpers (0.0.2) - GEM remote: http://rubygems.org/ specs: - abstract (1.0.0) - actionmailer (3.0.7) - actionpack (= 3.0.7) - mail (~> 2.2.15) - actionpack (3.0.7) - activemodel (= 3.0.7) - activesupport (= 3.0.7) - builder (~> 2.1.2) - erubis (~> 2.6.6) - i18n (~> 0.5.0) - rack (~> 1.2.1) - rack-mount (~> 0.6.14) - rack-test (~> 0.5.7) - tzinfo (~> 0.3.23) - activemodel (3.0.7) - activesupport (= 3.0.7) - builder (~> 2.1.2) - i18n (~> 0.5.0) - activerecord (3.0.7) - activemodel (= 3.0.7) - activesupport (= 3.0.7) - arel (~> 2.0.2) - tzinfo (~> 0.3.23) - activeresource (3.0.7) - activemodel (= 3.0.7) - activesupport (= 3.0.7) - activesupport (3.0.7) - arel (2.0.10) - builder (2.1.2) - erubis (2.6.6) - abstract (>= 1.0.0) - i18n (0.5.0) - mail (2.2.19) - activesupport (>= 2.3.6) + actionmailer (3.2.2) + actionpack (= 3.2.2) + mail (~> 2.4.0) + actionpack (3.2.2) + activemodel (= 3.2.2) + activesupport (= 3.2.2) + builder (~> 3.0.0) + erubis (~> 2.7.0) + journey (~> 1.0.1) + rack (~> 1.4.0) + rack-cache (~> 1.1) + rack-test (~> 0.6.1) + sprockets (~> 2.1.2) + activemodel (3.2.2) + activesupport (= 3.2.2) + builder (~> 3.0.0) + activerecord (3.2.2) + activemodel (= 3.2.2) + activesupport (= 3.2.2) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activeresource (3.2.2) + activemodel (= 3.2.2) + activesupport (= 3.2.2) + activesupport (3.2.2) + i18n (~> 0.6) + multi_json (~> 1.0) + arel (3.0.2) + builder (3.0.0) + diff-lcs (1.1.3) + erubis (2.7.0) + git (1.2.5) + haml (3.1.4) + hike (1.2.1) + i18n (0.6.0) + jeweler (1.8.3) + bundler (~> 1.0) + git (>= 1.2.5) + rake + rdoc + journey (1.0.3) + json (1.6.5) + mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) - mime-types (1.16) - polyglot (0.3.1) - rack (1.2.2) - rack-mount (0.6.14) - rack (>= 1.0.0) - rack-test (0.5.7) + mime-types (1.17.2) + multi_json (1.1.0) + polyglot (0.3.3) + rack (1.4.1) + rack-cache (1.2) + rack (>= 0.4) + rack-ssl (1.3.2) + rack + rack-test (0.6.1) rack (>= 1.0) - rails (3.0.7) - actionmailer (= 3.0.7) - actionpack (= 3.0.7) - activerecord (= 3.0.7) - activeresource (= 3.0.7) - activesupport (= 3.0.7) + rails (3.2.2) + actionmailer (= 3.2.2) + actionpack (= 3.2.2) + activerecord (= 3.2.2) + activeresource (= 3.2.2) + activesupport (= 3.2.2) bundler (~> 1.0) - railties (= 3.0.7) - railties (3.0.7) - actionpack (= 3.0.7) - activesupport (= 3.0.7) + railties (= 3.2.2) + railties (3.2.2) + actionpack (= 3.2.2) + activesupport (= 3.2.2) + rack-ssl (~> 1.3.2) rake (>= 0.8.7) - thor (~> 0.14.4) - rake (0.9.0) - shoulda (3.0.0.beta2) - shoulda-context (~> 1.0.0.beta1) - shoulda-matchers (~> 1.0.0.beta1) - shoulda-context (1.0.0.beta1) - shoulda-matchers (1.0.0.beta2) + rdoc (~> 3.4) + thor (~> 0.14.6) + rake (0.9.2.2) + rdoc (3.12) + json (~> 1.4) + rspec (2.9.0) + rspec-core (~> 2.9.0) + rspec-expectations (~> 2.9.0) + rspec-mocks (~> 2.9.0) + rspec-core (2.9.0) + rspec-expectations (2.9.0) + diff-lcs (~> 1.1.3) + rspec-mocks (2.9.0) + rspec-rails (2.9.0) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec (~> 2.9.0) + shoulda (3.0.1) + shoulda-context (~> 1.0.0) + shoulda-matchers (~> 1.0.0) + shoulda-context (1.0.0) + shoulda-matchers (1.0.0) + simplecov (0.6.1) + multi_json (~> 1.0) + simplecov-html (~> 0.5.3) + simplecov-html (0.5.3) + sprockets (2.1.2) + hike (~> 1.2) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) thor (0.14.6) - treetop (1.4.9) + tilt (1.3.3) + treetop (1.4.10) + polyglot polyglot (>= 0.3.1) - tzinfo (0.3.27) + tzinfo (0.3.32) PLATFORMS ruby DEPENDENCIES - jquery_ui_rails_helpers! - rails (>= 3.0.0) - shoulda (~> 3.0.0.beta2) + bundler (>= 1.0.0) + haml + jeweler (>= 1.5.2) + rails (>= 3) + rspec (>= 2) + rspec-rails (>= 2.5) + shoulda + simplecov diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..ec4ddd4 --- /dev/null +++ b/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2010 [name of plugin creator] + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0e2968b --- /dev/null +++ b/README.md @@ -0,0 +1,375 @@ +What Is It? +=========== + +It's a Ruby on Rails plugin that provides helpers that take some of the boilerplate out of generating HTML +for use with jQuery UI, see http://jqueryui.com/. + +Examples are in HAML, see http://haml.info/. + +Selectmenu +---------- + +See http://jquery-ui.googlecode.com/svn/branches/labs/selectmenu/index.html. + +Assets: + +* ui.selectmenu.css +* ui.selectmenu.jquery.js + +Also see: https://github.com/fnagel/jquery-ui for more, including updates (perhaps even look at the forks...) + +TabsHelper +---------- + +Helps generate HTML for use with the jQuery UI Tabs plugin. + + = ui_tabs do |widget| + - widget.tab('tab_one', 'Tab 1') do + Tab contents + - widget.tab('tab_two', 'Tab 2') do + Tab contents + +The above will generate this HTML in your view: + +
+ +
+ Tab contents +
+
+ Tab contents +
+
+ +Tabs will be rendered in the order you create them. + +You can pass HTML options to either the parent `div` or any individual tab's `div` as you like ... + + = ui_tabs :html => { :id => 'special_tabs', :class => 'zippy' } do |tab| + - widget.tab 'tab_one', 'Tab 1', :html => { :style => 'background: #FFF' } do + Tab contents + +The default DOM ID for the parent div is ... `id="tabs"` ... unless you pass in an HTML +option with a different value. + +Options for jQuery UI widgets will be passed in via a `:ui` parameter, but this isn't supported yet. + +AccordionHelper +--------------- + +Helps generate HTML for use with the jQuery UI Accordion widget. + +Usage is identical to the Tabs helper. + + = ui_accordion do |widget| + - widget.pane('accordion_one', 'Accordion 1') do + Accordion contents + - widget.pane('accordion_two', 'Accordion 2') do + Accordion contents + +The above will generate this HTML in your view: + +
+

Accordion 1

+
+ Accordion contents +
+

Accordion 2

+
+ Accordion contents +
+
+ + +DialogHelper +--------------- + +Helps generate HTML for use with the jQuery UI Dialog widget. + + = ui_dialog :html => { :id => 'my_dialog', :title => 'Dialog Title' } do |widget| + Dialog contents + +The above will generate this HTML in your view: + +
+ Dialog contents +
+ +Which you'll then work with in Javascript by the id: + + $('#my_dialog').dialog('open'); + +By default, dialogs will be set with `autoOpen: false`. In its current form, what the dialog helper +offers is perhaps not terribly useful in itself. When `:ui` parameters are supported, it ought to come into its own! + + +AutocompleteHelper +--------------- + +Helps generate HTML for use with the jQuery UI Autocomplete widget. + + = ui_autocomplete + +The above will generate this HTML in your view: + +
+ +
+ +You can pass your own form field and other html in a block, but you should be sure to include +an input of type text, as that's what the generated Javascript looks for. + + = ui_autocomplete :html => { :id => 'my_autocomplete' } do + = text_field :post + +The above will generate this HTML in your view: + +
+ +
+ +Javascript Generation +--------------------- + +By default, Javascript for the generated HTML is saved via `content_for` to the identifier `:jquery_ui_helpers`. +You can specify a custom identifier with the parameter `:script_for` + + = ui_tabs :script_for => :scripts do |widget| + ... + +You'll output that, at the bottom of the page beneath where you load jQuery, using: + + = yield :jquery_ui_helpers + +Progressbar +------------- + +Use it something like this: + + = ui_progressbar :html => {:id => 'uploader', :class => 'progress'} + +It also supports the :ui options hash for advanced config. + +Button +------------- + +Use it something like this: + + = ui_button :ui => {:icons => {primary:'ui-icon-gear'}} + + = ui_button :label => 'Save' + + = ui_button do + Save me + +It supports the `:ui` options hash for advanced config. + +Button Set +------------- + +Use it something like this: + + = ui_buttonset :labels => ['B', 'I'] + + = ui_buttonset :labels => ['B', 'I'], :type => 'radio' + + = ui_buttonset :labels => ['B', 'I'], :type => 'checkbox', :selected => ['B'] + +It also supports the :ui options hash for advanced config. By default the type is 'radio'. + +Slider +------------- + +Use it something like this: + + = ui_slider :html => {:id => 'rooms_slider', :class => 'slider'}, :ui => {:animate => true} + +SelectSlider +------------- + +This helper uses the Filamentgroup SelectSlider, which sits on top of the jQuery UI Slider +and enhances it with tooltips, labels and ARIA support etc. + +You can use it something like this: + + = ui_select_slider :html => {:id => 'rooms', :class => 'slider rooms'}, :ui => {:labels => 5}, :labels => (1..5).to_a, :range => [1,3] + + = ui_select_slider :html => {:id => 'sqm', :class => 'slider sqm'}, :ui => {:labels => 3}, :labels => (1..10).to_a.map{|v| v*10}, :range => [30,60] + +This will generate two `selectt` tags, one with a postfix id of '_from' and the other '_to', fx in the example above id='rooms_from' and id='rooms_to' + +You can do CSS tooltip customization. Here we want to make the tooltip more slim than the default 8 character width. For other style customizations, see 'ui_slider.extras.css' + + a#handle_rooms_to .ui-slider-tooltip, + a#handle_rooms_from .ui-slider-tooltip { + width: 1em !important; + margin-left: 0; + } + +For more details see http://www.filamentgroup.com. + +Reference article: http://filamentgroup.com/lab/update_jquery_ui_slider_from_a_select_element_now_with_aria_support/. + +Github project: https://github.com/filamentgroup/jQuery-Slider. + +Demo page: http://www.filamentgroup.com/examples/slider_v2/index.html. + +DateRangePicker +------------ + +Here is an example of an JSON options struture that can be passed in (see http://filamentgroup.com/examples/daterangepicker_v2/index2.php): + + { + presetRanges: [ + {text: 'Ad Campaign', dateStart: 'Today', dateEnd: '03/07/09' }, + {text: 'Spring Vacation', dateStart: '03/04/09', dateEnd: '03/08/09' }, + {text: 'Office Closed', dateStart: '04/04/09', dateEnd: '04/08/09' } + ], + posX: null, + posY: null, + arrows: true, + dateFormat: 'M d, yy', + rangeSplitter: 'to', + datepickerOptions: { + changeMonth: true, + changeYear: true + }, + onOpen:function(){ if(inframe){ $(window.parent.document).find('iframe:eq(1)').width(700).height('35em');} }, + onClose: function(){ if(inframe){ $(window.parent.document).find('iframe:eq(1)').width('100%').height('5em');} } + } + +Tree +----------- + +Examples: + + ui_tree :ui => {:expanded => 'li:first'} + + ui_branch :link => ['Google', 'www.google.com', {:id => 'google'}] do + [ + ui_leaf(:label => 'Hello'), + ui_leaf(:label => 'Bye') + ].safe_join + end + + ui_tree :ui => {:expanded => 'li:first'} do + ui_branch :link => ['Google', 'www.google.com', {:id => 'google'}] do + ui_leaf :label => 'Goodbye' + end + end + +Menu +------------ + +See `spec/examples`. Includes iPod "flyout" style menu. + + $('#flat').menu({ + content: $('#flat').next().html(), // grab content from this page + showSpeed: 400 + }); + + $('#hierarchy').menu({ + content: $('#hierarchy').next().html(), + crumbDefaultText: ' ' + }); + + $('#hierarchybreadcrumb').menu({ + content: $('#hierarchybreadcrumb').next().html(), + backLink: false + }); + + // or from an external source + $.get('menuContent.html', function(data){ // grab content from another page + $('#flyout').menu({ content: data, flyOut: true }); + }); + +a simple flat menu as simple as + + = ui_menu do + - [ui_menu_item(:label => 'Hello'), ui_menu_item(:label => 'Goodbye')].safe_join + +or with a little more spice and precision: + + = iu_menu do + [ + ui_menu_item(:link => ['Google', 'www.google.com', {:id => 'google'}]), + ui_menu_item(:link => ['Rails', 'www.rails.com', {:id => 'rails'}]), + ].safe_join + +or use the `ui_branch and ui_leaf` from tree to create a nested menu: + + = ui_menu :nested => true do + = ui_branch :link => ['Google', 'www.google.com', {:id => 'google'}] do + - ui_leaf :label => 'Goodbye' + +Checkbox +------------ + +See http://maninblack.info/_proj/jquery-ui-checkbox-radiobutton/demos/checkbox-radiobutton/. + +See http://www.openpave.org/~reg/jqueryui-checkbox.html. + + = ui_checkbox :label => 'B', :selected => true + = ui_checkboxes :labels => ['B', 'I'], :selected => ['B'] + +Same API as `ui_buttonset` and can still take the `:type` option, either `:radio` or checkbox +if `ui.checkbox_radio.jquery.js` is used. Otherwise, if `ui.checkbox.js` is used, you should only +use the `:checkbox` type (or better leave it out). + +Radiobutton +------------ + +See http://maninblack.info/_proj/jquery-ui-checkbox-radiobutton/demos/checkbox-radiobutton/. + + = ui_radiobutton :label => 'B', :selected => true + = ui_radiobuttons :labels => ['B', 'I'], :type => 'checkbox', :selected => ['B'] + +Same API as `ui_buttonset` but without the `:type` option + +Themeswitcher +------------ + +You might also find the themeswitcher for Rails useful: https://github.com/kristianmandrup/ui_themeswitcher. + +Rails asset pipeline +------------- + +CSS assets: + + fg.menu.jquery + + ui.checkbox + ui.checkbox_radio + ui.checkbox_radio_msoffice + + ui.daterange_picker + + ui.fileinput + + ui.select_slider + + ui.tree + +Javascript assets: + + enhance + fg.menu.jquery + + ui.button.jquery + + ui.checkbox.jquery + ui.checkbox_radio.jquery + + ui.daterange_picker.jquery + util.date + + ui.fileinput.jquery + + ui.select_slider.jquery + + ui.tree.jquery + + ui.widget.jquery diff --git a/README.textile b/README.textile deleted file mode 100644 index 85904f8..0000000 --- a/README.textile +++ /dev/null @@ -1,77 +0,0 @@ -h1. What Is It? - -These are some view helpers I use in Rails to better integrate jQuery UI into my sites. - -I hope you find them useful. - -h2. TabsHelper - -This helper simplifies the code required to use the jQuery UI Tab plugin. - -

-<% tabs_for do |tab| %>
-	<% tab.create('tab_one', 'Tab 1') do %>
-		# ... insert tab contents
-	<% end %>
-	<% tab.create('tab_two', 'Tab 2') do %>
-		# ... insert tab contents
-	<% end %>
-<% end %>
-
- -The above will generate this HTML in your view: - -

-
- -
- # ... insert tab contents -
-
- # ... insert tab contents -
-
-
- -Tabs will be rendered in the order you create them. - -You can easily render a tab conditionally by appending your condition to the end of -the 'create' block as such ... - -

-<% tab.create('profile_tab', 'Your Profile') do %>
-	# ... insert tab contents
-<% end unless @current_user.nil? %>
-
- -You can pass HTML options to either the parent DIV or any individual tab's -DIV as you like ... - -

-<% tabs_for(:class => 'zippy') do |tab| %>
-	<% tab.create('tab_one', 'Tab 1', :style => 'background: #FFF') do %>
-		# ... insert tab contents
-	<% end %>
-<% end %>
-
- -The default DOM ID for the parent div is ... id="tabs" ... unless you pass in an HTML -option with a different value. - -h2. AccordionsHelper - -This helper simplifies the code required to use JQuery UIs Accordion plugin. - -Usage is identical to the Tabs helper. - -

-<% accordions_for do |accordion| %>
-	<% accordion.create("dom_id", "accordion_title") do %>
-		# ... insert accordion contents
-	<% end %>
-<% end %>
-
- diff --git a/Rakefile b/Rakefile index d21efc6..4a69fc0 100644 --- a/Rakefile +++ b/Rakefile @@ -1,15 +1,33 @@ +require 'rubygems' require 'bundler' +begin + Bundler.setup(:default, :development) +rescue Bundler::BundlerError => e + $stderr.puts e.message + $stderr.puts "Run `bundle install` to install missing gems" + exit e.status_code +end require 'rake' -require 'rake/testtask' -Bundler::GemHelper.install_tasks - -desc 'Default: run unit tests.' -task :default => :test - -desc 'Test the simple_form plugin.' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' - t.libs << 'test' - t.pattern = 'test/**/*_test.rb' - t.verbose = true -end \ No newline at end of file + +require 'jeweler' +Jeweler::Tasks.new do |gem| + # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options + gem.name = "jquery_ui_rails_helpers" + gem.homepage = "https://github.com/beardedstudio/jquery_ui_rails_helpers" + gem.license = "MIT" + gem.summary = %Q{JQuery UI helpers you can use in your Rails apps} + gem.description = %Q{JQuery UI helpers you can use in your Rails apps} + gem.email = [""] + gem.authors = ["Bearded Studio", "CodeOfficer", "Kristian Mandrup"] + gem.files.include ['lib/*/*'] +end +Jeweler::RubygemsDotOrgTasks.new + +require 'rspec/core/rake_task' + +desc "Run RSpec" +RSpec::Core::RakeTask.new do |t| + t.verbose = false +end + +task :default => :spec diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..341cf11 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.2.0 \ No newline at end of file diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..7a1b5a1 --- /dev/null +++ b/init.rb @@ -0,0 +1,2 @@ +# Include hook code here +require 'jquery_ui_rails_helpers' diff --git a/install.rb b/install.rb new file mode 100644 index 0000000..f7732d3 --- /dev/null +++ b/install.rb @@ -0,0 +1 @@ +# Install hook code here diff --git a/jquery_ui_rails_helpers.gemspec b/jquery_ui_rails_helpers.gemspec index abff380..c7aa535 100644 --- a/jquery_ui_rails_helpers.gemspec +++ b/jquery_ui_rails_helpers.gemspec @@ -1,25 +1,159 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) -require "jquery_ui_rails_helpers/version" - Gem::Specification.new do |s| - s.name = "jquery_ui_rails_helpers" - s.version = JqueryUiRailsHelpers::VERSION - s.platform = Gem::Platform::RUBY - s.summary = "jQuery UI Rails Helpers" - s.authors = ["CodeOfficer"] - s.email = ["codeofficer@gmail.com"] - s.homepage = "http://www.codeofficer.com/" - s.description = "jQuery UI Rails Helpers" + s.name = "jquery_ui_rails_helpers" + s.version = "0.2.0" - # s.add_development_dependency("rails") - # s.add_development_dependency("shoulda") + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Bearded Studio", "CodeOfficer", "Kristian Mandrup"] + s.date = "2012-10-30" + s.description = "JQuery UI helpers you can use in your Rails apps" + s.email = [""] + s.extra_rdoc_files = [ + "README.md" + ] + s.files = [ + ".rspec", + "CHANGELOG", + "Gemfile", + "Gemfile.lock", + "MIT-LICENSE", + "README.md", + "Rakefile", + "VERSION", + "init.rb", + "install.rb", + "jquery_ui_rails_helpers.gemspec", + "lib/jquery_ui_rails_helpers.rb", + "lib/jquery_ui_rails_helpers/accordion_helper.rb", + "lib/jquery_ui_rails_helpers/autocomplete_helper.rb", + "lib/jquery_ui_rails_helpers/button_helper.rb", + "lib/jquery_ui_rails_helpers/buttonset_helper.rb", + "lib/jquery_ui_rails_helpers/checkbox_helper.rb", + "lib/jquery_ui_rails_helpers/daterange_helper.rb", + "lib/jquery_ui_rails_helpers/dialog_helper.rb", + "lib/jquery_ui_rails_helpers/fileinput_helper.rb", + "lib/jquery_ui_rails_helpers/jquery_ui_base.rb", + "lib/jquery_ui_rails_helpers/menu_helper.rb", + "lib/jquery_ui_rails_helpers/progressbar_helper.rb", + "lib/jquery_ui_rails_helpers/radio_helper.rb", + "lib/jquery_ui_rails_helpers/rails/engine.rb", + "lib/jquery_ui_rails_helpers/select_slider_helper.rb", + "lib/jquery_ui_rails_helpers/slider_helper.rb", + "lib/jquery_ui_rails_helpers/tabs_helper.rb", + "lib/jquery_ui_rails_helpers/tree_helper.rb", + "lib/jquery_ui_rails_helpers/tree_helper/ui_branch.rb", + "lib/jquery_ui_rails_helpers/tree_helper/ui_leaf.rb", + "lib/jquery_ui_rails_helpers/tree_helper/ui_tree.rb", + "spec/examples/checkbox_radio.js", + "spec/examples/full_menu.html", + "spec/examples/menu.html", + "spec/examples/ui.checkbox.js", + "spec/flex.css", + "spec/formtastic.html", + "spec/jquery_ui_rails_helpers/accordion_helper_spec.rb", + "spec/jquery_ui_rails_helpers/autocomplete_helper_spec.rb", + "spec/jquery_ui_rails_helpers/button_helper_spec.rb", + "spec/jquery_ui_rails_helpers/buttonset_helper_spec.rb", + "spec/jquery_ui_rails_helpers/checkbox_helper_spec.rb", + "spec/jquery_ui_rails_helpers/daterange_helper_spec.rb", + "spec/jquery_ui_rails_helpers/dialog_helper_spec.rb", + "spec/jquery_ui_rails_helpers/fileinput_helper_spec.rb", + "spec/jquery_ui_rails_helpers/menu_helper_spec.rb", + "spec/jquery_ui_rails_helpers/progressbar_helper_spec.rb", + "spec/jquery_ui_rails_helpers/radiobutton_helper_spec.rb", + "spec/jquery_ui_rails_helpers/radiobuttons_helper_spec.rb", + "spec/jquery_ui_rails_helpers/select_slider_helper_spec.rb", + "spec/jquery_ui_rails_helpers/slider_helper_spec.rb", + "spec/jquery_ui_rails_helpers/tabs_helper_spec.rb", + "spec/jquery_ui_rails_helpers/tree_helper_spec.rb", + "spec/spec_helper.rb", + "uninstall.rb", + "vendor/assets/images/fileinput/bg-btn.png", + "vendor/assets/images/fileinput/bg-submit.gif", + "vendor/assets/images/fileinput/icon-generic.gif", + "vendor/assets/images/fileinput/icon-image.gif", + "vendor/assets/images/fileinput/icon-media.gif", + "vendor/assets/images/fileinput/icon-zip.gif", + "vendor/assets/images/tree/icon-file.gif", + "vendor/assets/images/tree/icon-folder-open.gif", + "vendor/assets/images/tree/icon-folder.gif", + "vendor/assets/javascripts/date.js", + "vendor/assets/javascripts/enhance.js", + "vendor/assets/javascripts/fg.menu.jquery.js", + "vendor/assets/javascripts/jquery-1.8.0.js", + "vendor/assets/javascripts/jquery.selectboxes.js", + "vendor/assets/javascripts/ui.button.jquery.js", + "vendor/assets/javascripts/ui.checkbox.jquery.js", + "vendor/assets/javascripts/ui.checkbox_radio.jquery.js", + "vendor/assets/javascripts/ui.core.jquery.js", + "vendor/assets/javascripts/ui.datepicker.js", + "vendor/assets/javascripts/ui.daterange_picker.jquery.js", + "vendor/assets/javascripts/ui.daterange_picker.jquery.min.js", + "vendor/assets/javascripts/ui.fileinput.jquery.js", + "vendor/assets/javascripts/ui.select_slider.jquery.js", + "vendor/assets/javascripts/ui.selectmenu.jquery.js", + "vendor/assets/javascripts/ui.sweet_daterange.js", + "vendor/assets/javascripts/ui.sweet_input.js", + "vendor/assets/javascripts/ui.sweet_menu.js", + "vendor/assets/javascripts/ui.sweet_selectmenu.js", + "vendor/assets/javascripts/ui.tree.jquery.js", + "vendor/assets/javascripts/ui.widget.jquery.js", + "vendor/assets/javascripts/util.date.js", + "vendor/assets/stylesheets/fg.menu.jquery.css", + "vendor/assets/stylesheets/jquery-ui.css", + "vendor/assets/stylesheets/ui.checkbox.css", + "vendor/assets/stylesheets/ui.checkbox_radio.css", + "vendor/assets/stylesheets/ui.checkbox_radio_msoffice.css", + "vendor/assets/stylesheets/ui.daterange_picker.css", + "vendor/assets/stylesheets/ui.fileinput.css", + "vendor/assets/stylesheets/ui.menu.css", + "vendor/assets/stylesheets/ui.select_slider.css", + "vendor/assets/stylesheets/ui.selectmenu.css", + "vendor/assets/stylesheets/ui.sweet_input.css", + "vendor/assets/stylesheets/ui.sweet_selectmenu.css", + "vendor/assets/stylesheets/ui.tree.css" + ] + s.homepage = "https://github.com/beardedstudio/jquery_ui_rails_helpers" + s.licenses = ["MIT"] + s.require_paths = ["lib"] + s.rubygems_version = "1.8.24" + s.summary = "JQuery UI helpers you can use in your Rails apps" - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] + if s.respond_to? :specification_version then + s.specification_version = 3 - s.rubyforge_project = "jquery_ui_rails_helpers" + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 3"]) + s.add_development_dependency(%q, [">= 2"]) + s.add_development_dependency(%q, [">= 2.5"]) + s.add_development_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 1.0.0"]) + s.add_development_dependency(%q, [">= 1.5.2"]) + s.add_development_dependency(%q, [">= 0"]) + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 3"]) + s.add_dependency(%q, [">= 2"]) + s.add_dependency(%q, [">= 2.5"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 1.0.0"]) + s.add_dependency(%q, [">= 1.5.2"]) + s.add_dependency(%q, [">= 0"]) + end + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 3"]) + s.add_dependency(%q, [">= 2"]) + s.add_dependency(%q, [">= 2.5"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 1.0.0"]) + s.add_dependency(%q, [">= 1.5.2"]) + s.add_dependency(%q, [">= 0"]) + end end + diff --git a/lib/helpers/accordions_helper.rb b/lib/helpers/accordions_helper.rb deleted file mode 100644 index 665f0e9..0000000 --- a/lib/helpers/accordions_helper.rb +++ /dev/null @@ -1,47 +0,0 @@ -module AccordionsHelper - def accordions_for( *options, &block ) - raise ArgumentError, "Missing block" unless block_given? - raw AccordionsHelper::AccordionsRenderer.new( *options, &block ).render - end - - class AccordionsRenderer - - def initialize( options={}, &block ) - raise ArgumentError, "Missing block" unless block_given? - - @template = eval( 'self', block.binding ) - @options = options - @accordions = [] - - yield self - end - - def create( accordion_id, accordion_text, options={}, &block ) - raise "Block needed for AccordionsRenderer#CREATE" unless block_given? - @accordions << [ accordion_id, accordion_text, options, block ] - end - - def render - content = @accordions.collect do |accordion| - accordion_head(accordion) << accordion_body(accordion) - end.join - content_tag( :div, raw(content), { :id => :accordions }.merge( @options ) ) - end - - private # --------------------------------------------------------------------------- - - def accordion_head(accordion) - content_tag :h3, link_to(accordion[1], '#'), :id => accordion[0] - end - - def accordion_body(accordion) - content_tag( :div, &accordion[3] ) - end - - def method_missing( *args, &block ) - @template.send( *args, &block ) - end - - end -end - diff --git a/lib/helpers/javascripts_helper.rb b/lib/helpers/javascripts_helper.rb deleted file mode 100644 index c777e41..0000000 --- a/lib/helpers/javascripts_helper.rb +++ /dev/null @@ -1,19 +0,0 @@ -module JavascriptsHelper - - def stylesheet(*args) - content_for(:head) { stylesheet_link_tag(*args) } - end - - def javascript(*args) - content_for(:head) { javascript_include_tag(*args) } - end - - def field_id_for_js(f, attribute) - "#{f.object_name}[#{attribute.to_s.sub(/\?$/,"")}]".gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "") - end - - def field_name_for_js(f, attribute) - "#{f.object_name}[#{attribute.to_s.sub(/\?$/,"")}]" - end - -end \ No newline at end of file diff --git a/lib/helpers/tabs_helper.rb b/lib/helpers/tabs_helper.rb deleted file mode 100644 index 43aed85..0000000 --- a/lib/helpers/tabs_helper.rb +++ /dev/null @@ -1,65 +0,0 @@ -# http://forum.jquery.com/topic/jquery-datepicker-pick-multiple-dates -# module JqueryUiRailsHelpers - -module TabsHelper - def tabs_for( *options, &block ) - raise ArgumentError, "Missing block" unless block_given? - raw TabsHelper::TabsRenderer.new( *options, &block ).render - end - - class TabsRenderer - - def initialize( options={}, &block ) - raise ArgumentError, "Missing block" unless block_given? - - @template = eval( 'self', block.binding ) - @options = options - @tabs = [] - - yield self - end - - def create( tab_id, tab_text, options={}, &block ) - raise "Block needed for TabsRenderer#CREATE" unless block_given? - @tabs << [ tab_id, tab_text, options, block, {:ajax => false} ] - end - - def create_ajax( link, tab_text, options={}) - @tabs << [ link, tab_text, options, nil, {:ajax => true} ] - end - - def render - content_tag( :div, raw([render_tabs, render_bodies].join), { :id => :tabs }.merge( @options ) ) - end - - private # --------------------------------------------------------------------------- - - def render_tabs - content_tag :ul do - result = @tabs.collect do |tab| - if tab[4][:ajax] - content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "#{tab[0]}" ) ) - else - content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "##{tab[0]}" ) ) - end - end.join - raw(result) - end - end - - def render_bodies - @tabs.collect do |tab| - if tab[4][:ajax] - # there are no divs for ajaxed tabs - else - content_tag( :div, tab[2].merge( :id => tab[0] ), & tab[3]) - end - end.join.to_s - end - - def method_missing( *args, &block ) - @template.send( *args, &block ) - end - - end -end diff --git a/lib/jquery_ui_rails_helpers.rb b/lib/jquery_ui_rails_helpers.rb index bdb7974..1e35c2b 100644 --- a/lib/jquery_ui_rails_helpers.rb +++ b/lib/jquery_ui_rails_helpers.rb @@ -1,12 +1,21 @@ -require 'action_view' -require "jquery_ui_rails_helpers/version" -require 'helpers/javascripts_helper' -require 'helpers/tabs_helper' -require 'helpers/accordions_helper' +# JqueryUiRailsHelpers +require "jquery_ui_rails_helpers/jquery_ui_base" -module JqueryUiRailsHelpers -end +require "jquery_ui_rails_helpers/accordion_helper" +require "jquery_ui_rails_helpers/autocomplete_helper" +require "jquery_ui_rails_helpers/dialog_helper" +require "jquery_ui_rails_helpers/progressbar_helper" +require "jquery_ui_rails_helpers/slider_helper" +require "jquery_ui_rails_helpers/select_slider_helper" +require "jquery_ui_rails_helpers/tabs_helper" +require "jquery_ui_rails_helpers/button_helper" +require "jquery_ui_rails_helpers/buttonset_helper" +require "jquery_ui_rails_helpers/checkbox_helper" +require "jquery_ui_rails_helpers/radio_helper" +require "jquery_ui_rails_helpers/daterange_helper" +require "jquery_ui_rails_helpers/tree_helper" +require "jquery_ui_rails_helpers/fileinput_helper" +require "jquery_ui_rails_helpers/menu_helper" -ActionView::Base.send(:include, JavascriptsHelper) -ActionView::Base.send(:include, TabsHelper) -ActionView::Base.send(:include, AccordionsHelper) \ No newline at end of file +# rails engine +require 'jquery_ui_rails_helpers/rails/engine' diff --git a/lib/jquery_ui_rails_helpers/accordion_helper.rb b/lib/jquery_ui_rails_helpers/accordion_helper.rb new file mode 100644 index 0000000..47a9a87 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/accordion_helper.rb @@ -0,0 +1,46 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module AccordionHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_accordion(opts={}, &block) + raise ArgumentError, "Missing block" unless block_given? + ui(opts, JqueryUiAccordion, &block) + end + + class JqueryUiAccordion < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @panels = [] + @controller = controller + @ui_options = {}.merge( opts[:ui] ) + @html_options = { :id => :accordion }.merge( opts[:html] ) + + yield self if block_given? + end + + def panel(panel_id, panel_title, opts={}, &block) + content = @controller.capture(&block) + opts = { :html => {}, :header_html => {} }.merge(opts) + + header = content_tag( :h3, link_to( content_tag( :span, panel_title ), "#%s" % panel_id ), opts[:header_html] ) + panel = content_tag( :div, content, opts[:html].merge( :id => panel_id ) ) + + @panels << (header + panel) + end + + def render + # collect the html for our tabs + @html = content_tag( :div, @panels.join('').html_safe, @html_options) + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').accordion(%s); });" % [@html_options[:id], @ui_options.to_json] + + # return self, for chaining + self + end + + end + + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/autocomplete_helper.rb b/lib/jquery_ui_rails_helpers/autocomplete_helper.rb new file mode 100644 index 0000000..7b2a28e --- /dev/null +++ b/lib/jquery_ui_rails_helpers/autocomplete_helper.rb @@ -0,0 +1,33 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module AutocompleteHelper + include JqueryUiRailsHelpers::UiHelper, + ActionView::Helpers::TagHelper + + def ui_autocomplete(opts={}, &block) + ui(opts, JqueryUiAutocomplete, &block) + end + + class JqueryUiAutocomplete < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :autocomplete }.merge( opts[:html] ) + @ui_options = { :source => [] }.merge( opts[:ui] ) + @content = controller.capture(&block) if block_given? + @content = @content || tag(:input, :type => 'text') + end + + def render + # collect the html for our tabs + @html = content_tag( :div, @content.html_safe, @html_options) + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s input:text').autocomplete(%s); });" % [@html_options[:id], @ui_options.to_json] + + # return self, for chaining + self + end + + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/button_helper.rb b/lib/jquery_ui_rails_helpers/button_helper.rb new file mode 100644 index 0000000..0f55ef7 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/button_helper.rb @@ -0,0 +1,32 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module ButtonHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_button(opts={}, &block) + ui(opts, JqueryUiButton, &block) + end + + class JqueryUiButton < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :button }.merge( opts[:html] ) + @ui_options = {}.merge opts[:ui] + @content = controller.capture(&block) if block_given? + @content = @content || opts[:label] || "Press me!" + end + + def render + # collect the html for our tabs + @html = content_tag( :button, @content.html_safe, @html_options) + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').button(%s); });" % [@html_options[:id], @ui_options.to_json] + + # return self, for chaining + self + end + + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/buttonset_helper.rb b/lib/jquery_ui_rails_helpers/buttonset_helper.rb new file mode 100644 index 0000000..29739ac --- /dev/null +++ b/lib/jquery_ui_rails_helpers/buttonset_helper.rb @@ -0,0 +1,55 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module ButtonSetHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_buttonset(opts={}, &block) + ui(opts, JqueryUiButtonSet, &block) + end + + class JqueryUiButtonSet < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :buttonset }.merge( opts[:html] ) + @ui_options = {}.merge opts[:ui] + @labels = opts[:labels] || [] + @type = opts[:type] || 'radio' + @toolbar = {}.merge(opts[:toolbar] || {}) + @selected = opts[:selected] || [] + @content = controller.capture(&block) if block_given? + @content = @content || "" + end + + def render + @content = render_labels(@selected) unless @labels.empty? + # collect the html for our tabs + @html = content_tag( :button, @content.html_safe, @html_options) + + render_toolbar unless @toolbar.empty? + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').buttonset(%s); });" % [@html_options[:id], @ui_options.to_json] + + # return self, for chaining + self + end + + def render_toolbar + clz = "ui-widget-header ui-corner-all #{@toolbar[:class]}" + @html = content_tag(:span, @html, {:class => clz}) + end + + def render_labels selected = '' + index = 0 + @labels.inject("") do |res, label| + index += 1 + checked = selected.include?(label.to_s) + label_id = [@html_options[:id], @type, index.to_s].join '_' + label_tag = content_tag :label, label, {:for => label_id} + res << content_tag(:input, label_tag, {:id => label_id, :checked => checked, :type => @type}) + end + end + + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/checkbox_helper.rb b/lib/jquery_ui_rails_helpers/checkbox_helper.rb new file mode 100644 index 0000000..140e1b1 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/checkbox_helper.rb @@ -0,0 +1,57 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module CheckboxHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_checkboxes(opts={}, &block) + ui(opts, JqueryUiCheckbox, &block) + end + + def ui_checkbox(opts={}, &block) + # wrap args using same api + opts[:html] = opts[:html].merge(:id => :checkbox) if opts[:html] + opts[:labels] = [opts[:label]] + opts[:selected] = [opts[:label]] if opts[:selected] + + ui(opts, JqueryUiCheckbox, &block) + end + + class JqueryUiCheckbox < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :checkboxes }.merge( opts[:html] ) + @ui_options = {}.merge opts[:ui] + @labels = opts[:labels] || [] + @type = opts[:type] || 'checkbox' + @selected = opts[:selected] || [] + @disabled = opts[:disabled] || false + @content = controller.capture(&block) if block_given? + @content = @content || "" + end + + def render + @content = render_labels(@selected) unless @labels.empty? + # collect the html for our tabs + @html = render_labels selected + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').checkbox(%s); });" % [@html_options[:id], @ui_options.to_json] + + # return self, for chaining + self + end + + def render_labels selected = '' + index = 0 + @labels.inject("") do |res, label| + index += 1 + checked = selected.include?(label.to_s) + label_id = [@html_options[:id], @type, index.to_s].join '_' + label_tag = content_tag :label, label, {:for => label_id} + res << content_tag(:input, label_tag, {:id => label_id, :checked => checked, :type => @type, :disabled => @disabled}) + end + end + + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/daterange_helper.rb b/lib/jquery_ui_rails_helpers/daterange_helper.rb new file mode 100644 index 0000000..8464801 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/daterange_helper.rb @@ -0,0 +1,31 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module DateRangeHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_daterange(opts={}, &block) + ui(opts, JqueryUiDateRange, &block) + end + + class JqueryUiDateRange < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :daterange }.merge( opts[:html] ) + @ui_options = {}.merge opts[:ui] + @content = controller.capture(&block) if block_given? + @content = @content || "" + end + + def render + # collect the html for our tabs + @html = content_tag( :input, @content.html_safe, @html_options) + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').daterangepicker(%s); });" % [@html_options[:id], @ui_options.to_json] + + # return self, for chaining + self + end + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/dialog_helper.rb b/lib/jquery_ui_rails_helpers/dialog_helper.rb new file mode 100644 index 0000000..9e3b1ca --- /dev/null +++ b/lib/jquery_ui_rails_helpers/dialog_helper.rb @@ -0,0 +1,30 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module DialogHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_dialog(opts={}, &block) + ui(opts, JqueryUiDialog, &block) + end + + class JqueryUiDialog < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :dialog, :title => "" }.merge( opts[:html] ) + @content = controller.capture(&block) if block_given? + @content = @content || "" + end + + def render + # collect the html for our tabs + @html = content_tag( :div, @content.html_safe, @html_options) + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').dialog({ autoOpen: false }); });" % @html_options[:id] + + # return self, for chaining + self + end + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/fileinput_helper.rb b/lib/jquery_ui_rails_helpers/fileinput_helper.rb new file mode 100644 index 0000000..9a70aa6 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/fileinput_helper.rb @@ -0,0 +1,31 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module FileinputHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_fileinput(opts={}, &block) + ui(opts, JqueryUiFileinput, &block) + end + + class JqueryUiFileinput < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :fileinput }.merge( opts[:html] ) + @ui_options = {}.merge opts[:ui] + @content = controller.capture(&block) if block_given? + @content = @content || "" + end + + def render + # collect the html for our tabs + @html = content_tag( :input, @content.html_safe, @html_options.merge(:type => 'file')) + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').customFileInput(%s); });" % [@html_options[:id], @ui_options.to_json] + + # return self, for chaining + self + end + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/jquery_ui_base.rb b/lib/jquery_ui_rails_helpers/jquery_ui_base.rb new file mode 100644 index 0000000..8a65af8 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/jquery_ui_base.rb @@ -0,0 +1,22 @@ +module JqueryUiRailsHelpers + + module UiHelper + def ui(opts={}, renderer_class, &block) + opts = { :html => {}, :ui => {}, :script_for => :jquery_ui_helpers}.merge(opts) + + ui_widget = renderer_class.new(opts, self, &block).render + + content_for opts[:script_for], ui_widget.javascript + ui_widget.html + end + end + + class JqueryUiBase + include ActionView::Helpers::TagHelper, + ActionView::Helpers::UrlHelper, + ActionView::Helpers::CaptureHelper, + ActionView::Helpers::JavaScriptHelper + + attr_accessor :html, :javascript + end +end diff --git a/lib/jquery_ui_rails_helpers/menu_helper.rb b/lib/jquery_ui_rails_helpers/menu_helper.rb new file mode 100644 index 0000000..610b2d8 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/menu_helper.rb @@ -0,0 +1,79 @@ +require "jquery_ui_rails_helpers/tree_helper" + +module JqueryUI + module MenuHelper + include JqueryUiRailsHelpers::UiHelper + include ::JqueryUI::TreeHelper + + def ui_menu(opts={}, &block) + ui(opts, JqueryUiMenu, &block) + end + + def ui_menu_item(opts={}, &block) + ui(opts, JqueryUiMenuItem, &block) + end + + class JqueryUiMenu < JqueryUI::TreeHelper::JqueryUiTree + def initialize(opts={}, controller, &block) + super + @html_options = { :id => :menu }.merge( opts[:html] ) + @nested = opts[:nested] + end + + def render + super + end + + def inner_struct + nested? ? super : @content.html_safe + end + + def set_javascript + @javascript = javascript_tag "$(function(){ $('#%s').menu(%s); });" % [@html_options[:id], @ui_options.to_json] + end + + def nested? + @nested + end + end + # also use with ui_branch and ui_leaf from tree + + class JqueryUiMenuItem < JqueryUiRailsHelpers::JqueryUiBase + + def initialize(opts={}, controller, &block) + @ui_options = {}.merge opts[:ui] + @link = opts[:link] + @link_options = @link.extract_options! if @link + + id = 'menu_item' + id += ('_' + opts[:label].downcase) if opts[:label] + id += ('_' + @link_options[:id].downcase) if @link_options + + @html_options = { :id => id }.merge( opts[:html] ) + @label = opts[:label] || 'No item label' if !@link + @content = "" + end + + def render + add_label if @label + add_link if @link + + @html = content_tag :li, @content.html_safe, @html_options + self + end + + protected + + def add_link + href = @link.size > 1 ? @link.last : @link.first + label = @link.first + options = @link_options.merge(:href => href) + @content = content_tag(:a, label.html_safe, options) + end + + def add_label + @content = content_tag(:a, @label.html_safe, :href => '#') + end + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/progressbar_helper.rb b/lib/jquery_ui_rails_helpers/progressbar_helper.rb new file mode 100644 index 0000000..61ff01f --- /dev/null +++ b/lib/jquery_ui_rails_helpers/progressbar_helper.rb @@ -0,0 +1,31 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module ProgressbarHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_progressbar(opts={}, &block) + ui(opts, JqueryUiProgressbar, &block) + end + + class JqueryUiProgressbar < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :progressbar }.merge( opts[:html] ) + @ui_options = {}.merge opts[:ui] + @content = controller.capture(&block) if block_given? + @content = @content || "" + end + + def render + # collect the html for our tabs + @html = content_tag( :div, @content.html_safe, @html_options) + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').progressbar(%s); });" % [@html_options[:id], @ui_options.to_json] + + # return self, for chaining + self + end + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/radio_helper.rb b/lib/jquery_ui_rails_helpers/radio_helper.rb new file mode 100644 index 0000000..a9b5dab --- /dev/null +++ b/lib/jquery_ui_rails_helpers/radio_helper.rb @@ -0,0 +1,57 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module RadioHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_radios(opts={}, &block) + ui(opts, JqueryUiRadio, &block) + end + + def ui_radio(opts={}, &block) + # wrap args using same api + opts[:html] = opts[:html].merge(:id => :radio) if opts[:html] + opts[:labels] = [opts[:label]] + opts[:selected] = [opts[:label]] if opts[:selected] + + ui(opts, JqueryUiRadio, &block) + end + + class JqueryUiRadio < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :radios }.merge( opts[:html] ) + @ui_options = {}.merge opts[:ui] + @labels = opts[:labels] || [] + @type = opts[:type] || 'radio' + @selected = opts[:selected] || [] + @disabled = opts[:disabled] || false + @content = controller.capture(&block) if block_given? + @content = @content || "" + end + + def render + @content = render_labels(@selected) unless @labels.empty? + # collect the html for our tabs + @html = render_labels selected + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').radiobutton(%s); });" % [@html_options[:id], @ui_options.to_json] + + # return self, for chaining + self + end + + def render_labels selected = '' + index = 0 + @labels.inject("") do |res, label| + index += 1 + checked = selected.include?(label.to_s) + label_id = [@html_options[:id], @type, index.to_s].join '_' + label_tag = content_tag :label, label, {:for => label_id} + res << content_tag(:input, label_tag, {:id => label_id, :checked => checked, :type => @type, :disabled => @disabled}) + end + end + + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/rails/engine.rb b/lib/jquery_ui_rails_helpers/rails/engine.rb new file mode 100644 index 0000000..09e9f43 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/rails/engine.rb @@ -0,0 +1,28 @@ +module JqueryUiHelpers + module Rails + class Engine < ::Rails::Engine + initializer "setup for rails" do + # puts "JqueryUiHelpers engine loaded" + JqueryUiHelpers::Rails::Engine.add_view_ext + end + + def self.add_view_ext + helpers.each do |helper| + ActionView::Base.send :include, "JqueryUI::#{helper}".constantize + end + end + + def self.helpers + [ + :AccordionHelper, :AutocompleteHelper, :DialogHelper, :ProgressbarHelper, + :SliderHelper, :SelectSliderHelper, :TabsHelper, :ButtonHelper, :DateRangeHelper, + :TreeHelper, :FileinputHelper, :MenuHelper + ] + end + + def self.add_controller_ext + # ActionController::Base.send(:include, UiControllerExtensions) + end + end + end +end diff --git a/lib/jquery_ui_rails_helpers/select_slider_helper.rb b/lib/jquery_ui_rails_helpers/select_slider_helper.rb new file mode 100644 index 0000000..318be01 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/select_slider_helper.rb @@ -0,0 +1,83 @@ + # jQuery-Plugin - selectToUISlider - creates a UI slider component from a select element(s) + # by Scott Jehl, scott@filamentgroup.com + # http://www.filamentgroup.com + # reference article: http://www.filamentgroup.com/lab/update_jquery_ui_16_slider_from_a_select_element/ + # demo page: http://www.filamentgroup.com/examples/slider_v2/index.html + +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module SelectSliderHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_select_slider(opts={}, &block) + ui(opts, JqueryUiSelectSlider, &block) + end + + class JqueryUiSelectSlider < JqueryUiRailsHelpers::JqueryUiBase + # can also call with html_options[:ids] = ['from', 'to'] + # where each id is the "to" and "from" id of a selector for that range + def initialize(opts={}, controller, &block) + @html_options = { :id => :select_slider }.merge( opts[:html] ) + @ui_options = {}.merge opts[:ui] + + + @labels = {}.merge get_labels(opts[:labels] || []) + @range = opts[:range] + + @content = controller.capture(&block) if block_given? + @content = @content || "" + end + + def render + @content = render_labels unless @labels.empty? + + unless @range + @html = content_tag( :select, @content.html_safe, @html_options) + else + render_range_tags + ids = [id_from[:id], id_to[:id]] + + @html = content_tag( :select, @content_from.html_safe, @html_options.merge(id_from)) + @html << content_tag( :select, @content_to.html_safe, @html_options.merge(id_to)) + end + + # generate the javascript for jquery ui + @javascript = if ids + javascript_tag "$(function(){ $('select#%s, select#%s').selectToUISlider(%s); });" % [ids.first, ids.last, @ui_options.to_json] + else + javascript_tag "$(function(){ $('#%s').selectToUISlider(%s); });" % [@html_options[:id], @ui_options.to_json] + end + + # return self, for chaining + self + end + + protected + + def id_from + {:id => @html_options[:id].to_s + '_from'} + end + + def id_to + {:id => @html_options[:id].to_s + '_to'} + end + + def render_range_tags + @content_from = render_labels @range.first + @content_to = render_labels @range.last + end + + def get_labels labels + labels.kind_of?(Array) ? labels.inject({}){|res, val| res[val.to_s] = val.to_s; res} : labels + end + + def render_labels selected = '' + @labels.inject("") do |res, element| + sel = (selected && element.last.to_s == selected.to_s) + res << content_tag(:option, element.first.html_safe, {:value => element.last, :selected => sel}) + end + end + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/slider_helper.rb b/lib/jquery_ui_rails_helpers/slider_helper.rb new file mode 100644 index 0000000..d7f76b5 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/slider_helper.rb @@ -0,0 +1,31 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module SliderHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_slider(opts={}, &block) + ui(opts, JqueryUiSlider, &block) + end + + class JqueryUiSlider < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :slider }.merge( opts[:html] ) + @ui_options = {}.merge opts[:ui] + @content = controller.capture(&block) if block_given? + @content = @content || "" + end + + def render + # collect the html for our tabs + @html = content_tag( :div, @content.html_safe, @html_options) + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').slider(%s); });" % [@html_options[:id], @ui_options.to_json] + + # return self, for chaining + self + end + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/tabs_helper.rb b/lib/jquery_ui_rails_helpers/tabs_helper.rb new file mode 100644 index 0000000..3f448d4 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/tabs_helper.rb @@ -0,0 +1,43 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +module JqueryUI + module TabsHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_tabs(opts={}, &block) + raise ArgumentError, "Missing block" unless block_given? + ui(opts, JqueryUiTabs, &block) + end + + class JqueryUiTabs < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @tabs = [] + @tab_contents = [] + @controller = controller + @html_options = { :id => :tabs }.merge( opts[:html] ) + + yield self if block_given? + end + + def tab(tab_id, tab_text, opts={}, &block) + content = @controller.capture(&block) + opts = { :html => {} }.merge(opts) + + @tabs << content_tag( :li, link_to( content_tag( :span, tab_text ), "#%s" % tab_id ) ) + @tab_contents << content_tag( :div, content, opts[:html].merge( :id => tab_id ) ) + end + + def render + # collect the html for our tabs + output = content_tag( :ul, @tabs.join('').html_safe ) + @tab_contents.join('').html_safe + @html = content_tag( :div, output.html_safe, @html_options) + + # generate the javascript for jquery ui + @javascript = javascript_tag "$(function(){ $('#%s').tabs(); });" % @html_options[:id] + + # return self, for chaining + self + end + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/tree_helper.rb b/lib/jquery_ui_rails_helpers/tree_helper.rb new file mode 100644 index 0000000..6f0e736 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/tree_helper.rb @@ -0,0 +1,29 @@ +require "jquery_ui_rails_helpers/jquery_ui_base" + +[:tree, :branch, :leaf].each do |name| + require "jquery_ui_rails_helpers/tree_helper/ui_#{name}" +end + +class Array + def safe_join + self.join.html_safe + end +end + +module JqueryUI + module TreeHelper + include JqueryUiRailsHelpers::UiHelper + + def ui_tree(opts={}, &block) + ui(opts, JqueryUiTree, &block) + end + + def ui_branch(opts={}, &block) + ui(opts, JqueryUiBranch, &block) + end + + def ui_leaf(opts={}, &block) + ui(opts, JqueryUiLeaf, &block) + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/tree_helper/ui_branch.rb b/lib/jquery_ui_rails_helpers/tree_helper/ui_branch.rb new file mode 100644 index 0000000..6be0b0d --- /dev/null +++ b/lib/jquery_ui_rails_helpers/tree_helper/ui_branch.rb @@ -0,0 +1,48 @@ +module JqueryUI + module TreeHelper + class JqueryUiBranch < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = opts[:html] + @ui_options = {}.merge opts[:ui] + @link = opts[:link] + @label = opts[:label] + @content = controller.capture(&block) if block_given? + @block = block_given? + @content = @content || "" + end + + def render + add_link if @link + add_label if @label + + # collect the html for our node + @html = content_tag( :li, @content.html_safe, @html_options) + + # return self, for chaining + self + end + + protected + + def block? + @block + end + + def inner_content + block? ? content_tag(:ul, @content.html_safe) : @content.html_safe + end + + def add_label + @content = content_tag(:a, @label.html_safe, :href => '#') + inner_content + end + + def add_link + link_options = @link.extract_options! + href = @link.size > 1 ? @link.last : @link.first + label = @link.first + options = link_options.merge(:href => href) + @content = content_tag(:a, label.html_safe, options) + inner_content + end + end + end +end diff --git a/lib/jquery_ui_rails_helpers/tree_helper/ui_leaf.rb b/lib/jquery_ui_rails_helpers/tree_helper/ui_leaf.rb new file mode 100644 index 0000000..d2d688e --- /dev/null +++ b/lib/jquery_ui_rails_helpers/tree_helper/ui_leaf.rb @@ -0,0 +1,24 @@ +module JqueryUI + module TreeHelper + class JqueryUiLeaf < JqueryUiBranch + def initialize(opts={}, controller) + @html_options = opts[:html] + @ui_options = {}.merge opts[:ui] + @link = opts[:link] + @label = opts[:label] || 'No leaf label' if !@link + @content = "" + end + + def render + add_link if @link + add_label if @label + + # collect the html for our tabs + @html = content_tag( :li, @content.html_safe, @html_options) + + # return self, for chaining + self + end + end + end +end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/tree_helper/ui_tree.rb b/lib/jquery_ui_rails_helpers/tree_helper/ui_tree.rb new file mode 100644 index 0000000..80c9853 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/tree_helper/ui_tree.rb @@ -0,0 +1,59 @@ +module JqueryUI + module TreeHelper + class JqueryUiTree < JqueryUiRailsHelpers::JqueryUiBase + def initialize(opts={}, controller, &block) + @html_options = { :id => :tree }.merge( opts[:html] ) + @ui_options = {}.merge opts[:ui] + @link = opts[:link] + @root_options = opts[:root_opts] + @branch_options = opts[:branch_opts] + + @content = controller.capture(&block) if block_given? + @block = block_given? + @content = @content || "" + end + + def render + # collect the html for our tabs + + @html = content_tag( :ul, inner_content, @html_options) + + # generate the javascript for jquery ui + set_javascript + + # return self, for chaining + self + end + + protected + + def set_javascript + @javascript = javascript_tag "$(function(){ $('#%s').tree(%s); });" % [@html_options[:id], @ui_options.to_json] + end + + def block? + @block + end + + def inner_content + block? ? inner_struct : @content.html_safe + end + + def inner_struct + ul = link_label + content_tag( :ul, @content, @branch_options) + li = content_tag( :li, ul.html_safe, @root_options) + li.html_safe + end + + def link_label + return '' if !@link || @link.empty? + link_options = @link.extract_options! + href = @link.size > 1 ? @link.last : @link.first + label = @link.first + options = link_options.merge(:href => href) + content_tag(:a, label.html_safe, options) + end + end + end +end + diff --git a/lib/jquery_ui_rails_helpers/version.rb b/lib/jquery_ui_rails_helpers/version.rb deleted file mode 100644 index 31fc869..0000000 --- a/lib/jquery_ui_rails_helpers/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module JqueryUiRailsHelpers - VERSION = "0.0.2" -end diff --git a/spec/examples/checkbox_radio.js b/spec/examples/checkbox_radio.js new file mode 100644 index 0000000..93e6ab1 --- /dev/null +++ b/spec/examples/checkbox_radio.js @@ -0,0 +1,25 @@ +jQuery(function ($) { + $('#log').dblclick(function () { $('#log').empty(); }); +}); + +jQuery(function ($) { + $('input[type=checkbox]').checkbox().bind('ui-checkbox-changed' + +' ui-checkbox-enabled ui-checkbox-disabled' + +' ui-checkbox-focus ui-checkbox-blur', + function (event, info) { + $('#log').prepend('['+$(this).attr('id')+'] ' + $('label[for=' + $(this).attr('id') + ']').text() + ': ' + event.type + + '
'); + }); +}); + +jQuery(function ($) { + $('input[type=radio]').radiobutton().bind('ui-radiobutton-changed' + +' ui-radiobutton-enabled ui-radiobutton-disabled' + +' ui-radiobutton-focus ui-radiobutton-blur', + function (event, info) { + $('#log').prepend('['+$(this).attr('id')+'] ' + $('label[for=' + $(this).attr('id') + ']').text() + ': ' + event.type + + '
'); + }); + + $('input[type=radio][name=radiogroup3]').radiobutton('option', 'highlightGroup', true); +}); \ No newline at end of file diff --git a/spec/examples/full_menu.html b/spec/examples/full_menu.html new file mode 100644 index 0000000..ac29005 --- /dev/null +++ b/spec/examples/full_menu.html @@ -0,0 +1,93 @@ + + + + +Filament Group Lab + + + + + + + + + + + + + + + + + + + + + + + + + + + ipod-style menu w/ breadcrumb +