From 7d9859bb4c0b502279a3642be71c6e9e218d6fd7 Mon Sep 17 00:00:00 2001 From: Michael Hellein Date: Sat, 13 Nov 2010 14:19:25 -0500 Subject: [PATCH 01/63] followed some plugin conventions --- MIT-LICENSE | 20 ++++++++++++++++ README | 13 +++++++++++ Rakefile | 23 +++++++++++++++++++ {helpers => app/helpers}/accordions_helper.rb | 0 {helpers => app/helpers}/tabs_helper.rb | 0 init.rb | 1 + install.rb | 1 + lib/jquery_ui_rails_helpers.rb | 2 ++ lib/jquery_ui_rails_helpers/engine.rb | 8 +++++++ uninstall.rb | 1 + 10 files changed, 69 insertions(+) create mode 100644 MIT-LICENSE create mode 100644 README create mode 100644 Rakefile rename {helpers => app/helpers}/accordions_helper.rb (100%) rename {helpers => app/helpers}/tabs_helper.rb (100%) create mode 100644 init.rb create mode 100644 install.rb create mode 100644 lib/jquery_ui_rails_helpers.rb create mode 100644 lib/jquery_ui_rails_helpers/engine.rb create mode 100644 uninstall.rb 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 b/README new file mode 100644 index 0000000..61c2bd9 --- /dev/null +++ b/README @@ -0,0 +1,13 @@ +JqueryUiRailsHelpers +==================== + +Introduction goes here. + + +Example +======= + +Example goes here. + + +Copyright (c) 2010 [name of plugin creator], released under the MIT license diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..77c718c --- /dev/null +++ b/Rakefile @@ -0,0 +1,23 @@ +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test the jquery_ui_rails_helpers plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end + +desc 'Generate documentation for the jquery_ui_rails_helpers plugin.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'JqueryUiRailsHelpers' + rdoc.options << '--line-numbers' << '--inline-source' + rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('lib/**/*.rb') +end \ No newline at end of file diff --git a/helpers/accordions_helper.rb b/app/helpers/accordions_helper.rb similarity index 100% rename from helpers/accordions_helper.rb rename to app/helpers/accordions_helper.rb diff --git a/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb similarity index 100% rename from helpers/tabs_helper.rb rename to app/helpers/tabs_helper.rb diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..3c19a74 --- /dev/null +++ b/init.rb @@ -0,0 +1 @@ +# Include hook code here 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/lib/jquery_ui_rails_helpers.rb b/lib/jquery_ui_rails_helpers.rb new file mode 100644 index 0000000..1e90c16 --- /dev/null +++ b/lib/jquery_ui_rails_helpers.rb @@ -0,0 +1,2 @@ +# JqueryUiRailsHelpers +require 'jquery_ui_rails_helpers/engine' if defined?(Rails) \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/engine.rb b/lib/jquery_ui_rails_helpers/engine.rb new file mode 100644 index 0000000..4ee7c32 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/engine.rb @@ -0,0 +1,8 @@ +require "jquery_ui_rails_helpers" +require "rails" + +module JqueryUiRailsHelpers + class Engine < Rails::Engine + engine_name :jquery_ui_rails_helpers + end +end \ No newline at end of file diff --git a/uninstall.rb b/uninstall.rb new file mode 100644 index 0000000..9738333 --- /dev/null +++ b/uninstall.rb @@ -0,0 +1 @@ +# Uninstall hook code here From 3a0b15e8a57cbb8fa2a866f4cff899a3246d6bf2 Mon Sep 17 00:00:00 2001 From: Michael Hellein Date: Sat, 13 Nov 2010 20:16:56 -0500 Subject: [PATCH 02/63] refactored into a working plugin with rails 3, however only tabs are supported so far --- README | 13 ---- Rakefile | 71 ++++++++++++++----- app/helpers/tabs_helper.rb | 54 -------------- init.rb | 2 + lib/jquery_ui_rails_helpers.rb | 3 +- .../accordions_helper.rb | 0 lib/jquery_ui_rails_helpers/engine.rb | 8 --- lib/jquery_ui_rails_helpers/railtie.rb | 13 ++++ lib/jquery_ui_rails_helpers/tabs_helper.rb | 50 +++++++++++++ 9 files changed, 121 insertions(+), 93 deletions(-) delete mode 100644 README delete mode 100644 app/helpers/tabs_helper.rb rename {app/helpers => lib/jquery_ui_rails_helpers}/accordions_helper.rb (100%) delete mode 100644 lib/jquery_ui_rails_helpers/engine.rb create mode 100644 lib/jquery_ui_rails_helpers/railtie.rb create mode 100644 lib/jquery_ui_rails_helpers/tabs_helper.rb diff --git a/README b/README deleted file mode 100644 index 61c2bd9..0000000 --- a/README +++ /dev/null @@ -1,13 +0,0 @@ -JqueryUiRailsHelpers -==================== - -Introduction goes here. - - -Example -======= - -Example goes here. - - -Copyright (c) 2010 [name of plugin creator], released under the MIT license diff --git a/Rakefile b/Rakefile index 77c718c..3ae39d9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,23 +1,60 @@ +require 'rubygems' require 'rake' -require 'rake/testtask' require 'rake/rdoctask' -desc 'Default: run unit tests.' -task :default => :test +begin + gem 'rspec', '>= 1.2.6' + gem 'rspec-rails', '>= 1.2.6' + require 'spec' + require 'spec/rake/spectask' +rescue LoadError + begin + require 'rspec/core/rake_task.rb' + require 'rspec/core/version' + rescue LoadError + puts "[formtastic:] RSpec - or one of it's dependencies - is not available. Install it with: sudo gem install rspec-rails" + end +end + +desc 'Default: run unit specs.' +task :default => :spec + +if defined?(Spec) + desc 'Test the jquery_ui_rails_helpers plugin.' + Spec::Rake::SpecTask.new('spec') do |t| + t.spec_files = FileList['spec/**/*_spec.rb'] + t.spec_opts = ["-c"] + end + + desc 'Test the jquery_ui_rails_helpers plugin with specdoc formatting and colors' + Spec::Rake::SpecTask.new('specdoc') do |t| + t.spec_files = FileList['spec/**/*_spec.rb'] + t.spec_opts = ["--format specdoc", "-c"] + end -desc 'Test the jquery_ui_rails_helpers plugin.' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' - t.libs << 'test' - t.pattern = 'test/**/*_test.rb' - t.verbose = true + desc "Run all examples with RCov" + Spec::Rake::SpecTask.new('examples_with_rcov') do |t| + t.spec_files = FileList['spec/**/*_spec.rb'] + t.rcov = true + t.rcov_opts = ['--exclude', 'spec,Library'] + end end -desc 'Generate documentation for the jquery_ui_rails_helpers plugin.' -Rake::RDocTask.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'JqueryUiRailsHelpers' - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README') - rdoc.rdoc_files.include('lib/**/*.rb') -end \ No newline at end of file +if defined?(RSpec) + desc 'Test the jquery_ui_rails_helpers plugin.' + RSpec::Core::RakeTask.new('spec') do |t| + t.pattern = FileList['spec/**/*_spec.rb'] + end + + desc 'Test the jquery_ui_rails_helpers plugin with specdoc formatting and colors' + RSpec::Core::RakeTask.new('specdoc') do |t| + t.pattern = FileList['spec/**/*_spec.rb'] + end + + desc "Run all examples with RCov" + RSpec::Core::RakeTask.new('examples_with_rcov') do |t| + t.pattern = FileList['spec/**/*_spec.rb'] + t.rcov = true + t.rcov_opts = ['--exclude', 'spec,Library'] + end +end diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb deleted file mode 100644 index 8b4d624..0000000 --- a/app/helpers/tabs_helper.rb +++ /dev/null @@ -1,54 +0,0 @@ -module TabsHelper - - def tabs_for( *options, &block ) - raise ArgumentError, "Missing block" unless block_given? - - tabs = TabsHelper::TabsRenderer.new( *options, &block ) - tabs_html = tabs.render - concat tabs_html - 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 ] - end - - def render - content_tag( :div, [render_tabs, render_bodies], { :id => :tabs }.merge( @options ) ) - end - - private # --------------------------------------------------------------------------- - - def render_tabs - content_tag :ul do - @tabs.collect do |tab| - content_tag( :li, link_to( content_tag( :span, tab[1] ), "##{tab[0]}" ) ) - end.join - end - end - - def render_bodies - @tabs.collect do |tab| - content_tag( :div, capture( &tab[3] ), tab[2].merge( :id => tab[0] ) ) - end.join.to_s - end - - def method_missing( *args, &block ) - @template.send( *args, &block ) - end - - end - -end diff --git a/init.rb b/init.rb index 3c19a74..1701f0b 100644 --- a/init.rb +++ b/init.rb @@ -1 +1,3 @@ # Include hook code here +require 'jquery_ui_rails_helpers' +ActionView::Base.send :include, TabsHelper diff --git a/lib/jquery_ui_rails_helpers.rb b/lib/jquery_ui_rails_helpers.rb index 1e90c16..a962016 100644 --- a/lib/jquery_ui_rails_helpers.rb +++ b/lib/jquery_ui_rails_helpers.rb @@ -1,2 +1,3 @@ # JqueryUiRailsHelpers -require 'jquery_ui_rails_helpers/engine' if defined?(Rails) \ No newline at end of file +require File.join(File.dirname(__FILE__), *%w[jquery_ui_rails_helpers railtie]) if defined?(::Rails::Railtie) + diff --git a/app/helpers/accordions_helper.rb b/lib/jquery_ui_rails_helpers/accordions_helper.rb similarity index 100% rename from app/helpers/accordions_helper.rb rename to lib/jquery_ui_rails_helpers/accordions_helper.rb diff --git a/lib/jquery_ui_rails_helpers/engine.rb b/lib/jquery_ui_rails_helpers/engine.rb deleted file mode 100644 index 4ee7c32..0000000 --- a/lib/jquery_ui_rails_helpers/engine.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "jquery_ui_rails_helpers" -require "rails" - -module JqueryUiRailsHelpers - class Engine < Rails::Engine - engine_name :jquery_ui_rails_helpers - end -end \ No newline at end of file diff --git a/lib/jquery_ui_rails_helpers/railtie.rb b/lib/jquery_ui_rails_helpers/railtie.rb new file mode 100644 index 0000000..2896810 --- /dev/null +++ b/lib/jquery_ui_rails_helpers/railtie.rb @@ -0,0 +1,13 @@ +require "jquery_ui_rails_helpers" +require "jquery_ui_rails_helpers/tabs_helper" +# Accordions helper not yet refactored +#require "jquery_ui_rails_helpers/accordions_helper" +require "rails" + +module JqueryUiRailsHelpers + class Railtie < Rails::Railtie + initializer 'jquery_ui_rails_helpers.initialize', :after => :after_initialize do + ActionView::Base.send :include, TabsHelper + end + end +end 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..07e501c --- /dev/null +++ b/lib/jquery_ui_rails_helpers/tabs_helper.rb @@ -0,0 +1,50 @@ +module TabsHelper + include ActionView::Helpers::TagHelper, + ActionView::Helpers::UrlHelper + + def tabs_for(opts={}, &block) + @tabs = [] + @options = opts + + yield self if block_given? + + to_s + end + + def create(tab_id, tab_text, opts={}, &block) + content = capture(&block) + @tabs << JqueryUiTab.new(tab_id, tab_text, opts, content) + end + + private + + def to_s + tabs = '' + content = '' + + @tabs.each do |tab| + tabs << tab.render_tab + content << tab.render_content + end + output = tabs + content + + content_tag( :div, output.html_safe, { :id => :tabs }.merge( @options ) ) + end + + class JqueryUiTab + include ActionView::Helpers::TagHelper, + ActionView::Helpers::UrlHelper + + def initialize(tab_id, tab_text, options, content) + @html_id, @text, @options, @content = tab_id, tab_text, options, content + end + + def render_tab + content_tag( :li, link_to( content_tag( :span, @text ), "#%s" % @html_id ) ) + end + + def render_content + content_tag( :div, @content, @options.merge( :id => @html_id ) ) + end + end +end \ No newline at end of file From cfdda40c6493b1dbfd4493923bd834d55259b1ac Mon Sep 17 00:00:00 2001 From: Michael Hellein Date: Sun, 14 Nov 2010 18:27:03 -0500 Subject: [PATCH 03/63] added some tests --- Rakefile | 58 +++-------------------------------------- autotest/discover.rb | 2 ++ spec/lib/tabs_helper.rb | 26 ++++++++++++++++++ spec/spec_helper.rb | 11 ++++++++ 4 files changed, 43 insertions(+), 54 deletions(-) create mode 100644 autotest/discover.rb create mode 100644 spec/lib/tabs_helper.rb create mode 100644 spec/spec_helper.rb diff --git a/Rakefile b/Rakefile index 3ae39d9..c629b0d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,60 +1,10 @@ require 'rubygems' require 'rake' -require 'rake/rdoctask' +require 'rspec/core/rake_task' -begin - gem 'rspec', '>= 1.2.6' - gem 'rspec-rails', '>= 1.2.6' - require 'spec' - require 'spec/rake/spectask' -rescue LoadError - begin - require 'rspec/core/rake_task.rb' - require 'rspec/core/version' - rescue LoadError - puts "[formtastic:] RSpec - or one of it's dependencies - is not available. Install it with: sudo gem install rspec-rails" - end +desc "Run RSpec" +RSpec::Core::RakeTask.new do |t| + t.verbose = false end -desc 'Default: run unit specs.' task :default => :spec - -if defined?(Spec) - desc 'Test the jquery_ui_rails_helpers plugin.' - Spec::Rake::SpecTask.new('spec') do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] - t.spec_opts = ["-c"] - end - - desc 'Test the jquery_ui_rails_helpers plugin with specdoc formatting and colors' - Spec::Rake::SpecTask.new('specdoc') do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] - t.spec_opts = ["--format specdoc", "-c"] - end - - desc "Run all examples with RCov" - Spec::Rake::SpecTask.new('examples_with_rcov') do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] - t.rcov = true - t.rcov_opts = ['--exclude', 'spec,Library'] - end -end - -if defined?(RSpec) - desc 'Test the jquery_ui_rails_helpers plugin.' - RSpec::Core::RakeTask.new('spec') do |t| - t.pattern = FileList['spec/**/*_spec.rb'] - end - - desc 'Test the jquery_ui_rails_helpers plugin with specdoc formatting and colors' - RSpec::Core::RakeTask.new('specdoc') do |t| - t.pattern = FileList['spec/**/*_spec.rb'] - end - - desc "Run all examples with RCov" - RSpec::Core::RakeTask.new('examples_with_rcov') do |t| - t.pattern = FileList['spec/**/*_spec.rb'] - t.rcov = true - t.rcov_opts = ['--exclude', 'spec,Library'] - end -end diff --git a/autotest/discover.rb b/autotest/discover.rb new file mode 100644 index 0000000..f421dc5 --- /dev/null +++ b/autotest/discover.rb @@ -0,0 +1,2 @@ +Autotest.add_discovery { "rails" } +Autotest.add_discovery { "rspec2" } diff --git a/spec/lib/tabs_helper.rb b/spec/lib/tabs_helper.rb new file mode 100644 index 0000000..591103a --- /dev/null +++ b/spec/lib/tabs_helper.rb @@ -0,0 +1,26 @@ +require "spec_helper" + +describe TabsHelper do + include ActionView::Helpers + include Haml::Helpers + include TabsHelper + + # allow tabs.create to run by stubbing an output_buffer + attr_accessor :output_buffer + @output_buffer = "" + + it "should be empty, with an empty block" do + output = tabs_for do + end + output.should == "
" + end + + it "should be have one link, with one " do + output = tabs_for do |tabs| + tabs.create 'tab_one', 'Tab 1' do + # empty for now + end + end + output.should == "" + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..ffc53ee --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,11 @@ +# coding: utf-8 +require 'rubygems' +require 'rails' +require 'haml' +require 'active_support' +require 'action_pack' +require 'action_view' +require 'action_controller' +require 'action_view/template' +require 'action_view/test_case' +require 'jquery_ui_rails_helpers/tabs_helper' \ No newline at end of file From 12c8d1a5b82219c58ddbc12295047e257586c40d Mon Sep 17 00:00:00 2001 From: Michael Hellein Date: Sun, 14 Nov 2010 18:33:33 -0500 Subject: [PATCH 04/63] updated changelog --- CHANGELOG | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index a4b50b3..52f0d95 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +== 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. From 862f1ebd78e6e555ed6cf6dfc743afbe17450e3c Mon Sep 17 00:00:00 2001 From: Michael Hellein Date: Sun, 14 Nov 2010 19:26:07 -0500 Subject: [PATCH 05/63] added