Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

No longer maintained

  • Loading branch information...
commit b81f4db4569c859b000a9d10c5c284e87984def9 1 parent e36c64a
Petrik de Heus authored
20 MIT-LICENSE
View
@@ -1,20 +0,0 @@
-Copyright (c) 2008 Petrik de Heus
-
-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.
133 README.rdoc
View
@@ -1,132 +1,5 @@
= TableBuilder
-Rails builder for creating tables and calendars inspired by ActionView's FormBuilder.
-
-== Examples
-
-table_for has methods for each tag used in a table (<table>, <thead> <tr>, <td>, etc.)
-
-A basic example would look like this:
-
- @front_men = [FrontMan.new(1, 'David St. Hubbins'), FrontMan.new(2, 'David Lee Roth')]
-
- <% table_for(@front_men) do |t| %>
- <% t.head do %>
- <% t.r do %>
- <%= t.h('Id') %>
- <%= t.h('Name') %>
- <% end %>
- <% end %>
- <% t.body do |front_man| %>
- <% t.r do %>
- <%= t.d(h(front_man.id)) %>
- <%= t.d(h(front_man.name)) %>
- <% end %>
- <% end %>
- <% end %>
-
-You can pass an array to the head method:
-
- <%= t.head('Id', 'Name') %>
-
-
-The body and r method can be combined for easier usage:
-
- <% t.body_r do |front_man| %>
- <%= t.d(h(front_man.id)) %>
- <%= t.d(h(front_man.name)) %>
- <% end %>
-
-You can also pass blocks to the d and h methods for more flexibility:
-
- <%= t.d(:class => 'name') do %>
- <%= link_to(h(front_man.name), front_man_url(front_man)) %>
- <% end %>
-
-All tag methods are rails tag methods, so they can have extra html options.
-
- @drummers = [Drummer.new(1, 'John "Stumpy" Pepys'), Drummer.new(2, 'Eric "Stumpy Joe" Childs')]
-
- <% table_for(@drummers, :html => { :id => 'spinal_tap', :class => 'drummers'}) do |t| %>
- <% t.body_r(:class => 'row') do |e| %>
- <%= t.d(h(e.id), :title => 'id') %>
- <%= t.d(h(e.name)) %>
- <% end %>
- <% end %>
-
-... which produces the following html:
-
- <table class="drummers" id="spinal_tap">
- <tbody>
- <tr class="row">
- <td title="id">1</td>
- <td>John &quot;Stumpy&quot; Pepys</td>
- </tr>
- <tr class="row">
- <td title="id">2</td>
- <td>Eric &quot;Stumpy Joe&quot; Childs</td>
- </tr>
- </tbody>
- </table>
-
-You can customize the table by creating your own TableBuilder:
-
- <% table_for(@drummers, :builder => PagedTableBuilder) do |t| %>
-
-
-== Calendar Table
-
-calendar_for creates a table like table_for.
-All objects get sorted per day of the month
-
-A basic example would look like this:
-
- @tasks = Task.this_month
-
- <% calendar_for(@tasks) do |t| %>
- <%= t.head('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun') %>
- <% t.day do |day, tasks| %>
- <%= day.day %>
- <% tasks.each do |task| %>
- <%= h(task.name) %>
- <% end %>
- <% end %>
- <% end %>
-
-To show a different month you can pass the :year and :month options:
-
- <% calendar_for(@tasks, :year => 2009, :month => 1) do |t| %>
-
-To highlight a different day you can pass the :today option:
-
- <% calendar_for(@tasks, :today => Date.civil(2008, 12, 26)) do |t| %>
-
-By default the :date method is called on the objects for sorting.
-To use another method you can pass the :day_method option:
-
- <% t.day(:day_method => :calendar_date) do |day, tasks| %>
-
-If you want to add id's to your td tag you can pass a pattern:
-
- <% t.day(:id => 'day_%d') do |day, tasks| %>
-
-
-== Install
-
-script/plugin install git://github.com/p8/table_builder.git
-
-For a pre rails 3.0 table_builder:
- script/plugin install git://github.com/p8/table_builder.git
- cd vendor/plugins/table_builder/
- git checkout pre-rails-2.2
-
-For a pre rails 2.2 table_builder:
- script/plugin install git://github.com/p8/table_builder.git
- cd vendor/plugins/table_builder/
- git checkout pre-rails-2.2
-
-== Contributors
-
-Thanks to Sean Dague, F. Kocherga, John Duff.
-
-Copyright (c) 2008 Petrik de Heus, released under the MIT license
+No longer maintained.
+Use the following instead:
+https://github.com/watu/table_builder
39 Rakefile
View
@@ -1,39 +0,0 @@
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-
-desc 'Default: run unit tests.'
-task :default => :test
-
-desc 'Test the table_builder plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
-
-desc 'Generate documentation for the table_builder plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'TableBuilder'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
-
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "table_builder"
- gem.summary = %Q{Rails builder for creating tables and calendars inspired by ActionView's FormBuilder.}
- gem.description = %Q{Rails builder for creating tables and calendars inspired by ActionView's FormBuilder.}
- gem.email = ""
- gem.homepage = "http://github.com/maca/table_builder"
- gem.authors = ["Petrik de Heus"]
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
-end
1  VERSION
View
@@ -1 +0,0 @@
-0.2.0
2  init.rb
View
@@ -1,2 +0,0 @@
-require 'table_builder'
-
5 lib/table_builder.rb
View
@@ -1,5 +0,0 @@
-require(File.expand_path(File.join(File.dirname(__FILE__), 'table_builder', 'table_builder.rb')))
-require(File.expand_path(File.join(File.dirname(__FILE__), 'table_builder', 'calendar_helper.rb')))
-
-ActionView::Base.send :include, TableHelper
-ActionView::Base.send :include, CalendarHelper
151 lib/table_builder/calendar_helper.rb
View
@@ -1,151 +0,0 @@
-module CalendarHelper
-
- def calendar_for(objects, *args)
- raise ArgumentError, "Missing block" unless block_given?
- options = args.last.is_a?(Hash) ? args.pop : {}
- html_options = options[:html]
- builder = options[:builder] || CalendarBuilder
- calendar = options[:calendar] || Calendar
- content_tag(:table, nil, html_options) do
- yield builder.new(objects || [], self, calendar, options)
- end
- end
-
- class CalendarBuilder < TableHelper::TableBuilder
- def initialize(objects, template, calendar, options)
- super(objects, template, options)
- @calendar = calendar.new(options)
- @today = options[:today] || Time.now
- end
-
- def day(*args)
- raise ArgumentError, "Missing block" unless block_given?
- options = options_from_hash(args)
- day_method = options.delete(:day_method) || :date
- id_pattern = options.delete(:id)
- tbody do
- @calendar.objects_for_days(@objects, day_method).to_a.sort{|a1, a2| a1.first <=> a2.first }.each do |o|
- key, array = o
- day, objects = array
- concat(tag(:tr, options, true)) if(day.wday == @calendar.first_weekday)
- concat(tag(:td, td_options(day, id_pattern), true))
- yield(day, objects)
- concat('</td>')
- concat('</tr>') if(day.wday == @calendar.last_weekday)
- end
- end
- end
-
- private
-
- def objects_for_days
- @calendar.objects_for_days(@objects)
- end
-
- def td_options(day, id_pattern)
- options = {}
- css_classes = []
- css_classes << 'today' if day.strftime("%Y-%m-%d") == @today.strftime("%Y-%m-%d")
- css_classes << 'notmonth' if day.month != @calendar.month
- css_classes << 'weekend' if day.wday == 0 or day.wday == 6
- css_classes << 'future' if day > @today.to_date
- options[:class] = css_classes.join(' ') unless css_classes.empty?
- options[:id] = day.strftime(id_pattern) if id_pattern
- options
- end
-
- end
-
- class Calendar
- attr_accessor :first_weekday, :last_weekday, :month
-
- # :first lets you set the first day to start the calendar on (default is the first day of the given :month and :year).
- # :first => :today will use Date.today
- # :last lets you set the last day of the calendar (default is the last day of the given :month and :year).
- # :last => :thirty will show 30 days from :first
- # :last => :week will show one week
- def initialize(options={})
- @year = options[:year] || Time.now.year
- @month = options[:month] || Time.now.month
- @first_day_of_week = options[:first_day_of_week] || 0
- @first_weekday = first_day_of_week(@first_day_of_week)
- @last_weekday = last_day_of_week(@first_day_of_week)
-
- @first = options[:first]==:today ? Date.today : options[:first] || Date.civil(@year, @month, 1)
-
- if options[:last] == :thirty_days || options[:last] == :thirty
- @last = @first + 30
- elsif options[:last] == :one_week || options[:last] == :week
- @last = @first
- else
- @last = options[:last] || Date.civil(@year, @month, -1)
- end
-
- end
-
- def each_day
- first_day.upto(last_day) do |day|
- yield(day)
- end
- end
-
- def last_day
- last = @last
- while(last.wday % 7 != @last_weekday % 7)
- last = last.next
- end
- last
- end
-
- def first_day
- first = @first - 6
- while(first.wday % 7 != (@first_weekday) % 7)
- first = first.next
- end
- first
- end
-
- def objects_for_days(objects, day_method)
- unless @objects_for_days
- @objects_for_days = {}
- days.each{|day| @objects_for_days[day.strftime("%Y-%m-%d")] = [day, []]}
- objects.each do |o|
- date = o.send(day_method.to_sym).strftime("%Y-%m-%d")
- if @objects_for_days[date]
- @objects_for_days[date][1] << o
- end
- end
- end
- @objects_for_days
- end
-
- def days
- unless @days
- @days = []
- each_day{|day| @days << day}
- end
- @days
- end
-
- def mjdays
- unless @mjdays
- @mdays = []
- each_day{|day| @days << day}
- end
- @days
- end
-
- def first_day_of_week(day)
- day
- end
-
- def last_day_of_week(day)
- if day > 0
- day - 1
- else
- 6
- end
- end
- end
-
-end
126 lib/table_builder/table_builder.rb
View
@@ -1,126 +0,0 @@
-module TableHelper
-
- def table_for(objects, *args)
- raise ArgumentError, "Missing block" unless block_given?
- options = args.last.is_a?(Hash) ? args.pop : {}
- html_options = options[:html]
- builder = options[:builder] || TableBuilder
-
- content_tag(:table, html_options) do
- yield builder.new(objects || [], self, options)
- end
- end
-
- class TableBuilder
- include ::ActionView::Helpers::TagHelper
-
- def initialize(objects, template, options)
- raise ArgumentError, "TableBuilder expects an Array but found a #{objects.inspect}" unless objects.is_a? Array
- @objects, @template, @options = objects, template, options
- end
-
- def head(*args)
- if block_given?
- concat(tag(:thead, options_from_hash(args), true))
- yield
- concat('</thead>')
- else
- @num_of_columns = args.size
- content_tag(:thead,
- content_tag(:tr,
- args.collect { |c| content_tag(:th, c.html_safe)}.join('').html_safe
- )
- )
- end
- end
-
- def head_r(*args)
- raise ArgumentError, "Missing block" unless block_given?
- options = options_from_hash(args)
- head do
- concat(tag(:tr, options, true))
- yield
- concat('</tr>')
- end
- end
-
- def body(*args)
- raise ArgumentError, "Missing block" unless block_given?
- options = options_from_hash(args)
- tbody do
- @objects.each { |c| yield(c) }
- end
- end
-
- def body_r(*args)
- raise ArgumentError, "Missing block" unless block_given?
- options = options_from_hash(args)
- tbody do
- @objects.each { |c|
- concat(tag(:tr, options, true))
- yield(c)
- concat('</tr>'.html_safe)
- }
- end
- end
-
- def r(*args)
- raise ArgumentError, "Missing block" unless block_given?
- options = options_from_hash(args)
- tr(options) do
- yield
- end
- end
-
- def h(*args)
- if block_given?
- concat(tag(:th, options_from_hash(args), true))
- yield
- concat('</th>')
- else
- content = args.shift
- content_tag(:th, content, options_from_hash(args))
- end
- end
-
- def d(*args)
- if block_given?
- concat(tag(:td, options_from_hash(args), true))
- yield
- concat('</td>')
- else
- content = args.shift
- content_tag(:td, content, options_from_hash(args))
- end
- end
-
-
- private
-
- def options_from_hash(args)
- args.last.is_a?(Hash) ? args.pop : {}
- end
-
- def concat(tag)
- @template.safe_concat(tag)
- ""
- end
-
- def content_tag(tag, content, *args)
- options = options_from_hash(args)
- @template.content_tag(tag, content, options)
- end
-
- def tbody
- concat('<tbody>')
- yield
- concat('</tbody>')
- end
-
- def tr options
- concat(tag(:tr, options, true))
- yield
- concat('</tr>')
- end
- end
-end
4 lib/tasks/table_builder_tasks.rake
View
@@ -1,4 +0,0 @@
-# desc "Explaining what the task does"
-# task :table_builder do
-# # Task goes here
-# end
56 table_builder.gemspec
View
@@ -1,56 +0,0 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
-# -*- encoding: utf-8 -*-
-
-Gem::Specification.new do |s|
- s.name = %q{table_builder}
- s.version = "0.2.0"
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Petrik de Heus"]
- s.date = %q{2010-07-03}
- s.description = %q{Rails builder for creating tables and calendars inspired by ActionView's FormBuilder.}
- s.email = %q{}
- s.extra_rdoc_files = [
- "README.rdoc"
- ]
- s.files = [
- ".autotest",
- ".gitignore",
- "MIT-LICENSE",
- "README.rdoc",
- "Rakefile",
- "VERSION",
- "init.rb",
- "lib/table_builder.rb",
- "lib/table_builder/calendar_helper.rb",
- "lib/table_builder/table_builder.rb",
- "lib/tasks/table_builder_tasks.rake",
- "table_builder.gemspec",
- "test/calendar_helper_test.rb",
- "test/table_builder_test.rb",
- "test/test_helper.rb"
- ]
- s.homepage = %q{http://github.com/maca/table_builder}
- s.rdoc_options = ["--charset=UTF-8"]
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.7}
- s.summary = %q{Rails builder for creating tables and calendars inspired by ActionView's FormBuilder.}
- s.test_files = [
- "test/calendar_helper_test.rb",
- "test/table_builder_test.rb",
- "test/test_helper.rb"
- ]
-
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
-
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- else
- end
- else
- end
-end
-
190 test/calendar_helper_test.rb
View
@@ -1,190 +0,0 @@
-require File.join(File.dirname(__FILE__), 'test_helper.rb')
-
-class CalendarHelperTest < ActionView::TestCase
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::TagHelper
- include CalendarHelper
- attr_accessor :output_buffer
-
- def setup
- @events = [Event.new(3, 'Jimmy Page', Date.civil(2008, 12, 26)),
- Event.new(4, 'Robert Plant', Date.civil(2008, 12, 26))]
- end
-
- def test_calendar_for
- output = calendar_for(@events, :html => { :id => 'id', :style => 'style', :class => 'class'}) do |t|
- end
- expected = %(<table id="id" style="style" class="class">) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_calendar_for_without_an_array
- self.output_buffer = ''
- assert_raises(ArgumentError) do
- calendar_for('a') {|t| }
- end
- end
-
- def test_calendar_for_with_empty_array
- output = calendar_for([], :year=> 2008, :month => 12) do |c|
- c.day do |day, events|
- concat(events.collect{|e| e.id}.join)
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr><td class="notmonth weekend"></td><td></td><td></td><td></td><td></td><td></td><td class="weekend"></td></tr>) <<
- %(<tr><td class="weekend"></td><td></td><td></td><td></td><td></td><td></td><td class="weekend"></td></tr>) <<
- %(<tr><td class="weekend"></td><td></td><td></td><td></td><td></td><td></td><td class="weekend"></td></tr>) <<
- %(<tr><td class="weekend"></td><td></td><td></td><td></td><td></td><td></td><td class="weekend"></td></tr>) <<
- %(<tr><td class="weekend"></td><td></td><td></td><td></td><td class="notmonth"></td><td class="notmonth"></td><td class="notmonth weekend"></td></tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_calendar_for_with_events
- output = calendar_for(@events, :year=> 2008, :month => 12) do |c|
- c.day do |day, events|
- content = events.collect{|e| e.id}.join
- concat("(#{day.day})#{content}")
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr><td class="notmonth weekend">(30)</td><td>(1)</td><td>(2)</td><td>(3)</td><td>(4)</td><td>(5)</td><td class="weekend">(6)</td></tr>) <<
- %(<tr><td class="weekend">(7)</td><td>(8)</td><td>(9)</td><td>(10)</td><td>(11)</td><td>(12)</td><td class="weekend">(13)</td></tr>) <<
- %(<tr><td class="weekend">(14)</td><td>(15)</td><td>(16)</td><td>(17)</td><td>(18)</td><td>(19)</td><td class="weekend">(20)</td></tr>) <<
- %(<tr><td class="weekend">(21)</td><td>(22)</td><td>(23)</td><td>(24)</td><td>(25)</td><td>(26)34</td><td class="weekend">(27)</td></tr>) <<
- %(<tr><td class="weekend">(28)</td><td>(29)</td><td>(30)</td><td>(31)</td><td class="notmonth">(1)</td><td class="notmonth">(2)</td><td class="notmonth weekend">(3)</td></tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_calendar_for_sets_css_classes
- output = calendar_for([], :year=> 2008, :month => 12, :today => Date.civil(2008, 12, 15)) do |c|
- c.day do |day, events|
- concat(events.collect{|e| e.id}.join)
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr><td class="notmonth weekend"></td><td></td><td></td><td></td><td></td><td></td><td class="weekend"></td></tr>) <<
- %(<tr><td class="weekend"></td><td></td><td></td><td></td><td></td><td></td><td class="weekend"></td></tr>) <<
- %(<tr><td class="weekend"></td><td class="today"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="weekend future"></td></tr>) <<
- %(<tr><td class="weekend future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="weekend future"></td></tr>) <<
- %(<tr><td class="weekend future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="notmonth future"></td><td class="notmonth future"></td><td class="notmonth weekend future"></td></tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_calendar_for_thirty_days
- today = Date.civil(2008, 12, 15)
- output = calendar_for([], :today => today, :year=>2008, :month=>12, :first=>today, :last=>:thirty_days) do |c|
- c.day do |day, events|
- concat(events.collect{|e| e.id}.join)
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr><td class="weekend"></td><td class="today"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="weekend future"></td></tr>) <<
- %(<tr><td class="weekend future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="weekend future"></td></tr>) <<
- %(<tr><td class="weekend future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="notmonth future"></td><td class="notmonth future"></td><td class="notmonth weekend future"></td></tr>) <<
- %(<tr><td class="notmonth weekend future"></td><td class="notmonth future"></td><td class="notmonth future"></td><td class="notmonth future"></td><td class="notmonth future"></td><td class="notmonth future"></td><td class="notmonth weekend future"></td></tr>) <<
- %(<tr><td class="notmonth weekend future"></td><td class="notmonth future"></td><td class="notmonth future"></td><td class="notmonth future"></td><td class="notmonth future"></td><td class="notmonth future"></td><td class="notmonth weekend future"></td></tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_calendar_for_week
- today = Date.civil(2008, 12, 15)
- output = calendar_for([], :today => today, :year=>2008, :month=>12, :first=>today, :last=>:week) do |c|
- c.day do |day, events|
- concat(events.collect{|e| e.id}.join)
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr><td class="weekend"></td><td class="today"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="future"></td><td class="weekend future"></td></tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_calendar_for_sets_css_ids
- output = calendar_for([], :year=> 2008, :month => 12, :today => Date.civil(2008, 12, 15)) do |c|
- c.day(:id => 'day_%d') do |day, events|
- concat(events.collect{|e| e.id}.join)
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr><td class="notmonth weekend" id="day_30"></td><td id="day_01"></td><td id="day_02"></td><td id="day_03"></td><td id="day_04"></td><td id="day_05"></td><td class="weekend" id="day_06"></td></tr>) <<
- %(<tr><td class="weekend" id="day_07"></td><td id="day_08"></td><td id="day_09"></td><td id="day_10"></td><td id="day_11"></td><td id="day_12"></td><td class="weekend" id="day_13"></td></tr>) <<
- %(<tr><td class="weekend" id="day_14"></td><td class="today"id="day_15"></td><td class="future" id="day_16"></td><td class="future" id="day_17"></td><td class="future" id="day_18"></td><td class="future" id="day_19"></td><td class="future" class="weekend future" id="day_20"></td></tr>) <<
- %(<tr><td class="weekend future" id="day_21"></td><td class="future" id="day_22"></td><td class="future" id="day_23"></td><td class="future" id="day_24"></td><td class="future" id="day_25"></td><td class="future" id="day_26"></td><td class="weekend future" id="day_27"></td></tr>) <<
- %(<tr><td class="weekend future" id="day_28"></td><td class="future" id="day_29"></td><td class="future" id="day_30"></td><td class="future" id="day_31"></td><td class="notmonth future" id="day_01"></td><td class="notmonth future" id="day_02"></td><td class="notmonth weekend future" id="day_03"></td></tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
-end
-
-class CalendarHelperTest < ActionView::TestCase
-
- def setup
- @events = [Event.new(3, 'Jimmy Page', Date.civil(2008, 12, 26)),
- Event.new(4, 'Robert Plant', Date.civil(2008, 12, 26))]
- end
-
- def test_objects_for_days_with_events
- calendar = CalendarHelper::Calendar.new(:year=> 2008, :month => 12)
- objects_for_days = {}
- Date.civil(2008, 11, 30).upto(Date.civil(2009, 1, 3)){|day| objects_for_days[day.strftime("%Y-%m-%d")] = [day, []]}
- objects_for_days['2008-12-26'][1] = @events
- assert_equal objects_for_days, calendar.objects_for_days(@events, :date)
- end
-
- def test_objects_for_days
- calendar = CalendarHelper::Calendar.new(:year=> 2008, :month => 12)
- objects_for_days = {}
- Date.civil(2008, 11, 30).upto(Date.civil(2009, 1, 3)){|day| objects_for_days[day.strftime("%Y-%m-%d")] = [day, []]}
- assert_equal objects_for_days, calendar.objects_for_days([], :date)
- end
-
- def test_days
- calendar = CalendarHelper::Calendar.new(:year=> 2008, :month => 12)
- days = []
- Date.civil(2008, 11, 30).upto(Date.civil(2009, 1, 3)){|day| days << day}
- assert_equal days, calendar.days
- end
-
- def test_days_with_first_day_of_week_set
- calendar = CalendarHelper::Calendar.new(:year=> 2008, :month => 12, :first_day_of_week => 1)
- days = []
- Date.civil(2008, 12, 1).upto(Date.civil(2009, 1, 4)){|day| days << day}
- assert_equal days, calendar.days
- end
-
- def test_first_day
- calendar = CalendarHelper::Calendar.new(:year=> 2008, :month => 12)
- assert_equal Date.civil(2008, 11, 30), calendar.first_day
- end
-
- def test_last_day
- calendar = CalendarHelper::Calendar.new(:year=> 2008, :month => 12)
- assert_equal Date.civil(2009, 1, 3), calendar.last_day
- end
-
- def test_last_day_with_first_day_of_week_set
- calendar = CalendarHelper::Calendar.new(:year=> 2008, :month => 12, :first_day_of_week => 1)
- assert_equal Date.civil(2009, 1, 4), calendar.last_day
- end
-end
-
-class Event < Struct.new(:id, :name, :date); end
183 test/table_builder_test.rb
View
@@ -1,183 +0,0 @@
-require File.join(File.dirname(__FILE__), 'test_helper.rb')
-
-class TableBuilderTest < ActionView::TestCase
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::TagHelper
- include TableHelper
- attr_accessor :output_buffer
-
- def setup
- @drummer1 = Drummer.new(1, 'John "Stumpy" Pepys')
- @drummer2 = Drummer.new(2, 'Eric "Stumpy Joe" Childs')
- @drummer3 = Drummer.new(3, 'Peter "James" Bond')
- @drummer4 = Drummer.new(4, 'Mick Shrimpton (R. J. "Ric" Parnell)')
- end
-
- def test_table_for
- output = table_for([], :html => { :id => 'id', :style => 'style', :class => 'class'}) do |t|
- end
- expected = %(<table id="id" style="style" class="class">) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_table_for_without_an_array_raises_error
- assert_raises(ArgumentError) do
- table_for('a') {|t| }
- end
- end
-
- def test_head
- output = table_for([]) do |t|
- t.head do
- t.r do
- output_buffer.concat t.h('Id')
- output_buffer.concat t.h('Name')
- end
- end
- end
- expected = %(<table>) <<
- %(<thead>) <<
- %(<tr>) <<
- %(<th>Id</th>) <<
- %(<th>Name</th>) <<
- %(</tr>) <<
- %(</thead>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_head_r
- output = table_for([]) do |t|
- t.head_r do
- output_buffer.concat t.h('Id')
- output_buffer.concat t.h('Name')
- end
- end
- expected = %(<table>) <<
- %(<thead>) <<
- %(<tr>) <<
- %(<th>Id</th>) <<
- %(<th>Name</th>) <<
- %(</tr>) <<
- %(</thead>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_head_with_array
- output = table_for([@drummer1, @drummer2]) do |t|
- concat t.head('Id', 'Name')
- end
- expected = %(<table>) <<
- %(<thead>) <<
- %(<tr>) <<
- %(<th>Id</th>) <<
- %(<th>Name</th>) <<
- %(</tr>) <<
- %(</thead>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_body
- output = table_for([@drummer3, @drummer4]) do |t|
- t.body do |e|
- t.r do
- concat t.d(e.id)
- concat t.d(e.name)
- end
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr>) <<
- %(<td>3</td>) <<
- %(<td>Peter &quot;James&quot; Bond</td>) <<
- %(</tr>) <<
- %(<tr>) <<
- %(<td>4</td>) <<
- %(<td>Mick Shrimpton (R. J. &quot;Ric&quot; Parnell)</td>) <<
- %(</tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_body_r
- output = table_for([@drummer3, @drummer4]) do |t|
- t.body_r do |e|
- concat t.d(e.id)
- concat t.d(e.name)
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr>) <<
- %(<td>3</td>) <<
- %(<td>Peter &quot;James&quot; Bond</td>) <<
- %(</tr>) <<
- %(<tr>) <<
- %(<td>4</td>) <<
- %(<td>Mick Shrimpton (R. J. &quot;Ric&quot; Parnell)</td>) <<
- %(</tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_td_with_options
- output = table_for([@drummer1]) do |t|
- t.body_r do |e|
- output_buffer.concat t.d(e.name, :class => 'class')
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr>) <<
- %(<td class="class">John &quot;Stumpy&quot; Pepys</td>) <<
- %(</tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_td_with_block
- output = table_for([@drummer1]) do |t|
- t.body_r do |e|
- t.d do
- concat 'content'
- end
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr>) <<
- %(<td>content</td>) <<
- %(</tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
- def test_td_with_block_and_options
- output = table_for([@drummer1]) do |t|
- t.body_r do |e|
- t.d(:class => 'class') do
- concat 'content'
- end
- end
- end
- expected = %(<table>) <<
- %(<tbody>) <<
- %(<tr>) <<
- %(<td class="class">content</td>) <<
- %(</tr>) <<
- %(</tbody>) <<
- %(</table>)
- assert_dom_equal expected, output
- end
-
-end
-
-class Drummer < Struct.new(:id, :name); end
14 test/test_helper.rb
View
@@ -1,14 +0,0 @@
-require 'test/unit'
-
-require "rubygems"
-require 'active_support'
-require 'action_pack'
-require 'action_controller'
-require 'action_view'
-require 'action_controller'
-require 'action_view'
-require 'action_view/base'
-require 'action_view/template'
-require 'action_view/test_case'
-
-require(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'table_builder')))
Please sign in to comment.
Something went wrong with that request. Please try again.