fusionary-easel_helpers 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Josh Clayton
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,16 @@
1
+ easel_helpers.gemspec
2
+ lib/easel_helpers/helpers/date_helper.rb
3
+ lib/easel_helpers/helpers/form_helper.rb
4
+ lib/easel_helpers/helpers/grid_helper.rb
5
+ lib/easel_helpers/helpers/link_helper.rb
6
+ lib/easel_helpers/helpers/structure_helper.rb
7
+ lib/easel_helpers/helpers/table_helper.rb
8
+ lib/easel_helpers/helpers.rb
9
+ lib/easel_helpers/rails_partial_caching.rb
10
+ lib/easel_helpers.rb
11
+ Manifest
12
+ MIT-LICENSE
13
+ rails/init.rb
14
+ Rakefile
15
+ README.textile
16
+ tasks/easel_helpers_tasks.rake
data/README.textile ADDED
@@ -0,0 +1,3 @@
1
+ h1. Easel Helpers
2
+
3
+ Copyright (c) 2009 Josh Clayton, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'echoe'
5
+
6
+ Echoe.new("easel_helpers", "0.1.5") do |p|
7
+ p.description = "Fusionary Rails View Helpers"
8
+ p.url = "http://github.com/fusionary/easel_helpers"
9
+ p.author = "Joshua Clayton"
10
+ p.email = "joshua.clayton@gmail.com"
11
+ p.ignore_pattern = ["tmp/*"]
12
+ p.development_dependencies = ["actionview >= 2.1.0", "activesupport >= 2.1.0", "hpricot >= 0.8.1"]
13
+ end
14
+
15
+ desc 'Default: run unit tests.'
16
+ task :default => :test
17
+
18
+ desc 'Test the easel_helpers plugin.'
19
+ Rake::TestTask.new(:test) do |t|
20
+ t.libs << 'lib'
21
+ t.libs << 'test'
22
+ t.pattern = 'test/**/*_test.rb'
23
+ t.verbose = true
24
+ end
25
+
26
+ desc 'Generate documentation for the easel_helpers plugin.'
27
+ Rake::RDocTask.new(:rdoc) do |rdoc|
28
+ rdoc.rdoc_dir = 'rdoc'
29
+ rdoc.title = 'Easel-helpers'
30
+ rdoc.options << '--line-numbers' << '--inline-source'
31
+ rdoc.rdoc_files.include('README')
32
+ rdoc.rdoc_files.include('lib/**/*.rb')
33
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{easel_helpers}
5
+ s.version = "0.1.5"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Joshua Clayton"]
9
+ s.date = %q{2009-05-05}
10
+ s.description = %q{Fusionary Rails View Helpers}
11
+ s.email = %q{joshua.clayton@gmail.com}
12
+ s.extra_rdoc_files = ["lib/easel_helpers/helpers/date_helper.rb", "lib/easel_helpers/helpers/form_helper.rb", "lib/easel_helpers/helpers/grid_helper.rb", "lib/easel_helpers/helpers/link_helper.rb", "lib/easel_helpers/helpers/structure_helper.rb", "lib/easel_helpers/helpers/table_helper.rb", "lib/easel_helpers/helpers.rb", "lib/easel_helpers/rails_partial_caching.rb", "lib/easel_helpers.rb", "README.textile", "tasks/easel_helpers_tasks.rake"]
13
+ s.files = ["lib/easel_helpers/helpers/date_helper.rb", "lib/easel_helpers/helpers/form_helper.rb", "lib/easel_helpers/helpers/grid_helper.rb", "lib/easel_helpers/helpers/link_helper.rb", "lib/easel_helpers/helpers/structure_helper.rb", "lib/easel_helpers/helpers/table_helper.rb", "lib/easel_helpers/helpers.rb", "lib/easel_helpers/rails_partial_caching.rb", "lib/easel_helpers.rb", "Manifest", "MIT-LICENSE", "rails/init.rb", "Rakefile", "README.textile", "tasks/easel_helpers_tasks.rake", "easel_helpers.gemspec", "test/date_helper_test.rb", "test/form_helper_test.rb", "test/grid_helper_test.rb", "test/link_helper_test.rb", "test/structure_helper_test.rb", "test/table_helper_test.rb", "test/test_helper.rb"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/fusionary/easel_helpers}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Easel_helpers", "--main", "README.textile"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{easel_helpers}
19
+ s.rubygems_version = %q{1.3.2}
20
+ s.summary = %q{Fusionary Rails View Helpers}
21
+ s.test_files = ["test/date_helper_test.rb", "test/form_helper_test.rb", "test/grid_helper_test.rb", "test/link_helper_test.rb", "test/structure_helper_test.rb", "test/table_helper_test.rb", "test/test_helper.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_development_dependency(%q<actionview>, [">= 0", ">= 2.1.0"])
29
+ s.add_development_dependency(%q<activesupport>, [">= 0", ">= 2.1.0"])
30
+ s.add_development_dependency(%q<hpricot>, [">= 0", ">= 0.8.1"])
31
+ else
32
+ s.add_dependency(%q<actionview>, [">= 0", ">= 2.1.0"])
33
+ s.add_dependency(%q<activesupport>, [">= 0", ">= 2.1.0"])
34
+ s.add_dependency(%q<hpricot>, [">= 0", ">= 0.8.1"])
35
+ end
36
+ else
37
+ s.add_dependency(%q<actionview>, [">= 0", ">= 2.1.0"])
38
+ s.add_dependency(%q<activesupport>, [">= 0", ">= 2.1.0"])
39
+ s.add_dependency(%q<hpricot>, [">= 0", ">= 0.8.1"])
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ module EaselHelpers
2
+ module Helpers
3
+ module DateHelper
4
+
5
+ def datetime(dt = nil, default_text = "", format_string = :long)
6
+ dt ? dt.to_time.to_s(format_string) : default_text
7
+ end
8
+
9
+ def date(dt = nil, default_text = "", format_string = :long)
10
+ dt ? dt.to_date.to_s(format_string) : default_text
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ module EaselHelpers
2
+ module Helpers
3
+ module FormHelper
4
+
5
+ def submit_button(value, *args)
6
+ options = args.extract_options!
7
+ css_classes = ["btn"] << options.delete(:class) << args
8
+ content_tag(:button, "<span>#{value}</span>", {:type => "submit", :class => clean_css_classes(css_classes, {"last" => last_column})}.merge(options))
9
+ end
10
+
11
+ def set(*args, &block)
12
+ options = args.extract_options!
13
+ css_classes = [] << options.delete(:class) << args
14
+ css_classes << "text" unless other_than_grid?(args - ["last", last_column])
15
+
16
+ html = content_tag(:div, capture(&block), options.merge(:class => clean_css_classes(css_classes, {"last" => last_column})))
17
+ concat(html)
18
+ end
19
+
20
+ def fieldset(*args, &block)
21
+ options = args.extract_options!
22
+ options[:legend] ||= {}
23
+ css_classes = [] << options.delete(:class) << args
24
+ title = args.shift if args.first.is_a?(String)
25
+ legend = if title.blank?
26
+ ""
27
+ else
28
+ content_tag(:h3,
29
+ title,
30
+ {:class => clean_css_classes([options[:legend].delete(:class)] << "legend")}.merge(options[:legend]))
31
+ end
32
+
33
+ html = content_tag(:fieldset, legend + capture(&block), options.merge(:class => clean_css_classes(css_classes, {"last" => last_column})))
34
+ concat(html)
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,111 @@
1
+ module EaselHelpers
2
+ module Helpers
3
+ module GridHelper
4
+ MULTIPLES = {
5
+ :one_twentyfourth => (1/24.to_f),
6
+ :one_twelfth => (1/12.to_f),
7
+ :one_eigth => (1/8.to_f),
8
+ :one_sixth => (1/6.to_f),
9
+ :five_twentyfourths => (5/24.to_f),
10
+ :one_fourth => (1/4.to_f),
11
+ :seven_twentyfourths => (7/24.to_f),
12
+ :one_third => (1/3.to_f),
13
+ :three_eigths => (3/8.to_f),
14
+ :five_twelfths => (5/12.to_f),
15
+ :eleven_twentyfourths => (11/24.to_f),
16
+ :one_half => (1/2.to_f),
17
+ :half => (1/2.to_f),
18
+ :thirteen_twentyfourths => (13/24.to_f),
19
+ :seven_twelfths => (7/12.to_f),
20
+ :five_eigths => (5/8.to_f),
21
+ :two_thirds => (2/3.to_f),
22
+ :seventeen_twentyfourths => (17/24.to_f),
23
+ :three_fourths => (3/4.to_f),
24
+ :nineteen_twentyfourths => (19/24.to_f),
25
+ :five_sixths => (5/6.to_f),
26
+ :seven_eigths => (7/8.to_f),
27
+ :eleven_twelfths => (11/12.to_f),
28
+ :twentythree_twentyfourths => (23/24.to_f),
29
+ :full => (1.to_f)
30
+ }.freeze
31
+ MULTIPLE_FRACTIONS = MULTIPLES.keys.map {|k| k.to_s }.freeze
32
+
33
+ def last_column
34
+ "col-last"
35
+ end
36
+
37
+ def column(size=nil, *args, &block)
38
+ @_easel_column_count ||= application_width
39
+ col(size, *args, &block)
40
+ end
41
+
42
+ def container(size=nil, *args, &block)
43
+ args = args.insert(0, :container)
44
+ column(size, *args, &block)
45
+ end
46
+
47
+ def method_missing_with_easel_widths(call, *args)
48
+ # filter out any initial helper calls
49
+ found = false
50
+ MULTIPLE_FRACTIONS.each do |w|
51
+ found = true and break if call.to_s.include?(w)
52
+ end
53
+ method_missing_without_easel_widths(call, *args) and return unless found
54
+
55
+ # one of the widths is somewhere in the helper call; let's find it
56
+ call.to_s =~ /^((append|prepend|col)_)?(.+)$/
57
+ class_name = $2 || "col"
58
+ class_width = $3
59
+
60
+ if MULTIPLES.keys.include?(class_width.to_sym)
61
+ width = @_easel_column_count || application_width
62
+ "#{class_name}-#{(width*MULTIPLES[class_width.to_sym]).to_i}"
63
+ else
64
+ method_missing_without_easel_widths(call, *args)
65
+ end
66
+ end
67
+
68
+ alias_method_chain :method_missing, :easel_widths
69
+
70
+ private
71
+
72
+ def application_width; 24; end
73
+
74
+ def increase_depth(size)
75
+ @_easel_current_width = @_easel_column_count.to_s
76
+ @_easel_column_count = size.to_s =~ /^\d+$/ ? size.to_s.to_i : (@_easel_column_count*MULTIPLES[size]).to_i
77
+ end
78
+
79
+ def decrease_depth(size)
80
+ @_easel_column_count = size.is_a?(Integer) ? @_easel_current_width.to_i : (@_easel_column_count/MULTIPLES[size]).to_i
81
+ @_easel_current_width = nil
82
+ end
83
+
84
+ def col(size=nil, *args, &block)
85
+ size = :full if size.blank?
86
+
87
+ increase_depth(size)
88
+ output_tag = generate_output_tag(size, args, &block)
89
+
90
+ if block_given? && block_is_within_action_view?(block)
91
+ concat(output_tag)
92
+ decrease_depth(size)
93
+ else
94
+ decrease_depth(size)
95
+ output_tag
96
+ end
97
+ end
98
+
99
+ def generate_output_tag(size, *args, &block)
100
+ options = args.extract_options!
101
+
102
+ css_classes = [] << options.delete(:class) << args
103
+ css_classes << "col-#{@_easel_column_count}" unless options.delete(:suppress_col)
104
+ css_classes << last_column if size.to_sym == :full && @_easel_column_count != application_width
105
+
106
+ content_tag(:div, capture(&block), {:class => clean_css_classes(css_classes, {"last" => last_column})}.merge(options))
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,21 @@
1
+ module EaselHelpers
2
+ module Helpers
3
+ module LinkHelper
4
+
5
+ def link_button(*args, &block)
6
+ doc = Hpricot(link_to(*args, &block))
7
+ doc.at("a").inner_html = "<span>#{doc.at("a").inner_html}</span>"
8
+ (doc/:a).add_class("btn")
9
+ doc.to_html
10
+ end
11
+
12
+ def link_to_email(email_address, *args)
13
+ options = args.extract_options!
14
+ link = args.first.is_a?(String) ? h(args.first) : email_address
15
+ return link if email_address.blank?
16
+ link_to link, "mailto:#{email_address}", options
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ module EaselHelpers
2
+ module Helpers
3
+ module StructureHelper
4
+
5
+ def blockquote(*args, &block)
6
+ options = args.extract_options!
7
+ author = options.delete(:author)
8
+
9
+ bq = content_tag(:blockquote,
10
+ (option_quote = textilize(options.delete(:quote))).blank? ? capture(&block) : option_quote
11
+ )
12
+
13
+ html = if author
14
+ content_tag(:div, bq + content_tag(:cite, author), :class => "quote-cited")
15
+ else
16
+ bq
17
+ end
18
+
19
+ concat(html)
20
+ end
21
+
22
+ def body(*args)
23
+ options = args.extract_options!
24
+ @_page_body_attributes ||= {}
25
+
26
+ css_classes = [] << @_page_body_attributes.delete(:class) << args
27
+ @_page_body_attributes = @_page_body_attributes.merge(options)
28
+ @_page_body_attributes[:class] = clean_css_classes(css_classes)
29
+
30
+ if block_given?
31
+ block = lambda { yield }
32
+ html = content_tag(:body, capture(&block), @_page_body_attributes)
33
+ return concat(html)
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ module EaselHelpers
2
+ module Helpers
3
+ module TableHelper
4
+
5
+ def zebra_row(options = {}, &block)
6
+ cycle_list = options.delete(:cycle_list) || [nil, "alt"]
7
+ css_classes = [cycle(*cycle_list)] << options.delete(:class)
8
+ html = content_tag(:tr, capture(&block),
9
+ options.merge(:class => clean_css_classes(css_classes)))
10
+ concat(html)
11
+ end
12
+
13
+ def recordset(*args, &block)
14
+ options = args.extract_options!
15
+ options[:table] ||= {}
16
+
17
+ headers = []
18
+ (options[:headers] || []).each_with_index do |header, index|
19
+ head = [header].flatten
20
+ opts = head.extract_options!
21
+
22
+ css_classes = [] << case index
23
+ when 0 then "first"
24
+ when (options[:headers].size - 1) then "last"
25
+ end
26
+
27
+ css_classes << opts.delete(:class)
28
+
29
+ headers << if head.first =~ /^\<th/
30
+ th = Hpricot(head.first)
31
+ th.at("th")["class"] = clean_css_classes([th.at("th")['class'].to_s, css_classes])
32
+ th.to_html
33
+ else
34
+ content_tag(:th, head.first, opts.merge(:class => clean_css_classes(css_classes)))
35
+ end
36
+ end
37
+
38
+ table_css_classes = ["recordset"] << options[:table].delete(:class) << args
39
+
40
+ html = content_tag(:table,
41
+ content_tag(:thead, content_tag(:tr, headers.to_s)) + capture(&block),
42
+ options[:table].merge(:class => clean_css_classes(table_css_classes)))
43
+
44
+ reset_cycle
45
+ concat(html)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,68 @@
1
+ require "easel_helpers/helpers/date_helper"
2
+ require "easel_helpers/helpers/form_helper"
3
+ require "easel_helpers/helpers/link_helper"
4
+ require "easel_helpers/helpers/structure_helper"
5
+ require "easel_helpers/helpers/table_helper"
6
+ require "easel_helpers/helpers/grid_helper"
7
+
8
+ module EaselHelpers
9
+ module Helpers
10
+ include DateHelper
11
+ include FormHelper
12
+ include LinkHelper
13
+ include StructureHelper
14
+ include TableHelper
15
+ include GridHelper
16
+
17
+ protected
18
+
19
+ def other_than_grid?(classes)
20
+ ([classes].flatten.map(&:to_s) - EaselHelpers::Helpers::GridHelper::MULTIPLE_FRACTIONS).any?
21
+ end
22
+
23
+ def clean_css_classes(string_or_array, replace = {})
24
+ css_classes = [] + standardize_css_classes(string_or_array)
25
+
26
+ if replace.any?
27
+ replace.keys.each do |k|
28
+ if css_classes.include? k
29
+ css_classes.delete(k)
30
+ css_classes << replace[k]
31
+ end
32
+ end
33
+ end
34
+
35
+ if css_classes.any? && (fractions = css_classes & EaselHelpers::Helpers::GridHelper::MULTIPLE_FRACTIONS).any?
36
+ fractions.each do |f|
37
+ css_classes.delete(f)
38
+ css_classes << self.send(f)
39
+ end
40
+ end
41
+
42
+ css_classes.map(&:strip).reject {|s| s.blank? }.uniq.join(" ").strip
43
+ end
44
+
45
+ private
46
+
47
+ def standardize_css_classes(string_or_array)
48
+ [string_or_array].flatten.join(" ").split(/ /)
49
+ end
50
+
51
+ BLOCK_CALLED_FROM_ERB = 'defined? __in_erb_template'
52
+
53
+ if RUBY_VERSION < '1.9.0'
54
+ # Check whether we're called from an erb template.
55
+ # We'd return a string in any other case, but erb <%= ... %>
56
+ # can't take an <% end %> later on, so we have to use <% ... %>
57
+ # and implicitly concat.
58
+ def block_is_within_action_view?(block)
59
+ block && eval(BLOCK_CALLED_FROM_ERB, block)
60
+ end
61
+ else
62
+ def block_is_within_action_view?(block)
63
+ block && eval(BLOCK_CALLED_FROM_ERB, block.binding)
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,38 @@
1
+ module ActionView
2
+ module Partials
3
+ private
4
+
5
+ def render_partial_with_easel(*args)
6
+ path = args.first[:partial]
7
+ locals = args.last
8
+
9
+ easel_cached_column_counts = session[:easel_cached_column_counts] ||= {}
10
+
11
+ if easel_cached_column_counts.keys.include?(path)
12
+ @_easel_column_count = locals[:easel_width] || easel_cached_column_counts[path]
13
+ easel_cached_column_counts[path] = @_easel_column_count
14
+ else
15
+ easel_cached_column_counts[path] = @_easel_column_count if @_easel_column_count.is_a?(Fixnum) && path !~ /^layout/
16
+ end
17
+
18
+ render_partial_without_easel(*args)
19
+ end
20
+
21
+ alias_method_chain :render_partial, :easel
22
+ end
23
+ end
24
+
25
+ module EaselHelpers
26
+ module PartialCaching
27
+ def self.included(base)
28
+ base.send :include, EaselHelpers::PartialCaching::InstanceMethods
29
+ base.before_filter :clear_easel_cache
30
+ end
31
+
32
+ module InstanceMethods
33
+ def clear_easel_cache
34
+ session[:easel_cached_column_counts] = nil unless request.xhr?
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ require "hpricot"
2
+ require "easel_helpers/helpers"
3
+ require "easel_helpers/rails_partial_caching"
data/rails/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "easel_helpers"
2
+
3
+ ActionView::Base.send :include, EaselHelpers::Helpers
4
+ ActionController::Base.send :include, EaselHelpers::PartialCaching
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :easel_helpers do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,59 @@
1
+ require 'test_helper'
2
+
3
+ class DateHelperTest < ActiveSupport::TestCase
4
+ include EaselHelpers::Helpers::DateHelper
5
+
6
+ context "datetime helper" do
7
+ should "default to an empty string if date is not supplied" do
8
+ assert_equal "", datetime(nil)
9
+ end
10
+
11
+ should "default to passed default text if date is not supplied" do
12
+ assert_equal "default text", datetime(nil, "default text")
13
+ end
14
+
15
+ should "default to :long format for date" do
16
+ timestamp = Time.now
17
+ assert_equal timestamp.to_s(:long), datetime(timestamp)
18
+ end
19
+
20
+ should "use passed format if applicable" do
21
+ timestamp = Time.now
22
+ assert_equal timestamp.to_s(:short), datetime(timestamp, "", :short)
23
+ end
24
+
25
+ should "convert passed data to a time" do
26
+ datestamp = Date.today
27
+ timestamp = datestamp.to_time
28
+ assert_equal timestamp.to_s(:long), datetime(datestamp)
29
+ end
30
+ end
31
+
32
+ context "date helper" do
33
+ should "default to an empty string if date is not supplied" do
34
+ assert_equal "", date(nil)
35
+ end
36
+
37
+ should "default to passed default text if date is not supplied" do
38
+ assert_equal "default text", date(nil, "default text")
39
+ end
40
+
41
+ should "default to :long format for date" do
42
+ datestamp = Date.today
43
+ assert_equal datestamp.to_s(:long), date(datestamp)
44
+ end
45
+
46
+ should "use passed format if applicable" do
47
+ datestamp = Date.today
48
+ assert_equal datestamp.to_s(:short), date(datestamp, "", :short)
49
+ end
50
+
51
+ should "convert passed data to a time" do
52
+ timestamp = Time.now
53
+ datestamp = timestamp.to_date
54
+
55
+ assert_equal datestamp.to_s(:long), date(timestamp)
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,109 @@
1
+ require 'test_helper'
2
+
3
+ class FormHelperTest < EaselHelpers::ViewTestCase
4
+
5
+ context "submit_button" do
6
+
7
+ should "default with the correct structure" do
8
+ show_view "<%= submit_button 'Create' %>" do
9
+ assert_select "button.btn[type=submit]" do
10
+ assert_select "span", "Create"
11
+ end
12
+ end
13
+ end
14
+
15
+ should "allow adding additional classes" do
16
+ show_view "<%= submit_button 'Create', 'adtl-class', :dumb %>" do
17
+ assert_select "button.btn.adtl-class.dumb[type=submit]" do
18
+ assert_select "span", "Create"
19
+ end
20
+ end
21
+ end
22
+
23
+ should "handle additional attributes set" do
24
+ show_view "<%= submit_button 'Create', :kls, :id => 'my-id', :type => 'image' %>" do
25
+ assert_select "button.btn.kls#my-id[type=image]" do
26
+ assert_select "span", "Create"
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ context "set" do
34
+
35
+ should "default with the correct structure" do
36
+ show_view "<% set do %>words<% end %>" do
37
+ assert_select "div.text", "words"
38
+ end
39
+ end
40
+
41
+ should "allow adding/overriding classes" do
42
+ show_view "<% set :checkbox do %>words<% end %>" do
43
+ assert_select "div.checkbox", "words"
44
+ end
45
+ end
46
+
47
+ should "handle additional attributes set" do
48
+ show_view "<% set :id => 'custom-id' do %>words<% end %>" do
49
+ assert_select "div.text#custom-id", "words"
50
+ end
51
+ end
52
+
53
+ should "assign default class if width class is passed as the only class" do
54
+ show_view "<% set :half do %>words<% end %>" do
55
+ assert_select "div.text.col-12", "words"
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ context "fieldset" do
62
+
63
+ should "default with the correct structure" do
64
+ show_view "<% fieldset do %>words<% end %>" do
65
+ assert_select "fieldset", "words"
66
+ end
67
+ end
68
+
69
+ should "assign the first argument as the legend if it is a string" do
70
+ show_view "<% fieldset 'User Information' do %>words<% end %>" do
71
+ assert_select "fieldset", /words/ do
72
+ assert_select "h3.legend", "User Information"
73
+ end
74
+ end
75
+ end
76
+
77
+ should "allow adding fieldset classes" do
78
+ show_view "<% fieldset :hform, 'col-last' do %>words<% end %>" do
79
+ assert_select "fieldset.hform.col-last", "words"
80
+ end
81
+ end
82
+
83
+ should "allow adding fieldset classes and a legend" do
84
+ show_view "<% fieldset 'User Information', :hform, 'col-last' do %>words<% end %>" do
85
+ assert_select "fieldset.hform.col-last", /words/ do
86
+ assert_select "h3.legend", "User Information"
87
+ end
88
+ end
89
+ end
90
+
91
+ should "allow assignment of legend attributes" do
92
+ show_view "<% fieldset 'User Information', :hform, :legend => {:class => 'lgnd', :id => 'legend-id'} do %>words<% end %>" do
93
+ assert_select "fieldset.hform", /words/ do
94
+ assert_select "h3.legend.lgnd#legend-id", "User Information"
95
+ end
96
+ end
97
+ end
98
+
99
+ should "allow assignment of fieldset attributes" do
100
+ show_view "<% fieldset 'User Information', :hform, :id => 'my-fieldset' do %>words<% end %>" do
101
+ assert_select "fieldset.hform#my-fieldset", /words/ do
102
+ assert_select "h3.legend", "User Information"
103
+ end
104
+ end
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class GridHelperTest < EaselHelpers::ViewTestCase
4
+ test "a basic structure can be generated" do
5
+ template = %(
6
+ <% container do %>
7
+ <% column do %>
8
+ <% column :half do %>
9
+ <% column :one_third do %>
10
+ one third of one half of 24 is 4
11
+ <% end %>
12
+ <% column :one_third, :last, prepend_one_third do %>
13
+ one third of one half of 24 is 4 (but prepended 4 as well)
14
+ <% end %>
15
+ <hr/>
16
+ more text
17
+ <% end %>
18
+ <% column :half, :last do %>
19
+ second column
20
+ <% end %>
21
+ <hr/>
22
+ text
23
+ <% end %>
24
+ <% end %>
25
+ )
26
+
27
+ show_view template do
28
+ assert_select ".container", 1
29
+ assert_select ".col-24", 1
30
+ assert_select ".col-12", 2
31
+ assert_select ".col-4", 2
32
+ assert_select ".prepend-4", 1
33
+ assert_select ".col-24.col-last", 0
34
+ assert_select ".col-12.col-last", 1
35
+ assert_select ".col-4.col-last", 1
36
+ assert_select "hr", 2
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ class LinkHelperTest < EaselHelpers::ViewTestCase
4
+ context "link_button" do
5
+
6
+ should "default with the correct structure" do
7
+ show_view "<%= link_button 'Link Text', '#' %>" do
8
+ assert_select "a.btn[href=#]" do
9
+ assert_select "span", "Link Text"
10
+ end
11
+ end
12
+ end
13
+
14
+ should "allow the same assignment as link_to" do
15
+ show_view "<%= link_button 'Link Text', '#', :class => 'my-button', :id => 'link-text' %>" do
16
+ assert_select "a.btn.my-button#link-text[href=#]" do
17
+ assert_select "span", "Link Text"
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ context "link_to_email" do
25
+ should "default with the correct structure" do
26
+ show_view "<%= link_to_email 'test@example.com' %>" do
27
+ assert_select "a[href=mailto:test@example.com]", "test@example.com"
28
+ end
29
+ end
30
+
31
+ should "allow override of link text as the first argument after email" do
32
+ show_view "<%= link_to_email 'test@example.com', 'Send an email to Test User' %>" do
33
+ assert_select "a[href=mailto:test@example.com]", "Send an email to Test User"
34
+ end
35
+ end
36
+
37
+ should "allow the same assignment as link_to" do
38
+ show_view "<%= link_to_email 'test@example.com', :class => 'test-user-email', :id => 'user_1_email' %>" do
39
+ assert_select "a.test-user-email#user_1_email[href=mailto:test@example.com]", "test@example.com"
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ class StructureHelperTest < EaselHelpers::ViewTestCase
4
+
5
+ context "blockquote" do
6
+
7
+ should "default with the correct structure" do
8
+ show_view "<% blockquote do %>My quoted text<% end %>" do
9
+ assert_select "blockquote", "My quoted text"
10
+ end
11
+ end
12
+
13
+ should "default with the correct structure when an author is set" do
14
+ show_view "<% blockquote :author => 'W. Shakespeare' do %>All the world's a stage<% end %>" do
15
+ assert_select "div.quote-cited" do
16
+ assert_select "blockquote", "All the world's a stage"
17
+ assert_select "cite", "W. Shakespeare"
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ context "body" do
25
+
26
+ should "allow passing a block structure" do
27
+ show_view %(
28
+ <% body do %>body goes here<% end %>
29
+ ) do
30
+ assert_select "body", "body goes here"
31
+ end
32
+ end
33
+
34
+ should "allow passing arguments" do
35
+ show_view %(
36
+ <% body :home, 'home-index', 'logged-in', :id => 'application' do %>body goes here<% end %>
37
+ ) do
38
+ assert_select "body#application.home.home-index.logged-in", "body goes here"
39
+ end
40
+ end
41
+
42
+ should "allow multiple body definitions that set attributes" do
43
+ show_view %(
44
+ <% body :home, 'logged-in' %>
45
+ <% body :id => 'application' %>
46
+ <% body 'home-index', :id => 'application-override' do %>body goes here<% end %>
47
+ ) do
48
+ assert_select "body#application-override.home.home-index.logged-in", "body goes here"
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,112 @@
1
+ require 'test_helper'
2
+
3
+ class TableHelperTest < EaselHelpers::ViewTestCase
4
+
5
+ context "zebra_row" do
6
+
7
+ should "default with the correct structure" do
8
+ show_view "<table><% zebra_row do %>no class<% end %><% zebra_row do %>alt class<% end %></table>" do
9
+ assert_select "tr:first-child", "no class"
10
+ assert_select "tr.alt:last-child", "alt class"
11
+ end
12
+ end
13
+
14
+ should "allow override of the cycle list" do
15
+ show_view %(
16
+ <table>
17
+ <% (colors = %w(red white blue)).each do |color| %>
18
+ <% zebra_row :cycle_list => colors do %>the color <%= color %><% end %>
19
+ <% end %>
20
+ </table>
21
+ ) do
22
+ assert_select "tr.red:first-child", "the color red"
23
+ assert_select "tr.white", "the color white"
24
+ assert_select "tr.blue:last-child", "the color blue"
25
+ end
26
+ end
27
+
28
+ should "allow option assignment" do
29
+ show_view "<% zebra_row :id => 'my-id', :class => 'custom-class' do %>user 1<% end %>" do
30
+ assert_select "tr#my-id.custom-class", "user 1"
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ context "recordset" do
37
+
38
+ should "default with the correct structure" do
39
+ show_view %(<% recordset do %>rows<% end %>) do
40
+ assert_select "table.recordset", "rows"
41
+ end
42
+ end
43
+
44
+ should "allow headers be set" do
45
+ show_view %(<% recordset :headers => ["Header 1", "Header 2", "Header 3"] do %><tbody>rows</tbody><% end %>) do
46
+ assert_select "table.recordset" do
47
+ assert_select "thead" do
48
+ assert_select "tr" do
49
+ assert_select "th.first", "Header 1"
50
+ assert_select "th", "Header 2"
51
+ assert_select "th.last", "Header 3"
52
+ end
53
+ end
54
+ assert_select "tbody", "rows"
55
+ end
56
+ end
57
+ end
58
+
59
+ should "allow headers to have attributes set" do
60
+ show_view %(
61
+ <% recordset :headers => [["Header 1", {:class => "mine", :id => "over"}]] do %>
62
+ <tbody>rows</tbody>
63
+ <% end %>
64
+ ) do
65
+ assert_select "table.recordset" do
66
+ assert_select "thead" do
67
+ assert_select "tr" do
68
+ assert_select "th#over.first.mine", "Header 1"
69
+ end
70
+ end
71
+ assert_select "tbody", "rows"
72
+ end
73
+ end
74
+ end
75
+
76
+ should "allow classes be assigned in a comma-delimited manner" do
77
+ show_view %(<% recordset "my-recordset", "car-list" do %><% end %>) do
78
+ assert_select "table.recordset.my-recordset.car-list"
79
+ end
80
+ end
81
+
82
+ should "allow additional attributes be set on the recordset" do
83
+ show_view %(<% recordset :headers => %w(One Two Three), :table => {:id => "my-id", :class => "my-recordset"} do %><% end %>) do
84
+ assert_select "table#my-id.recordset.my-recordset" do
85
+ assert_select "thead" do
86
+ assert_select "tr" do
87
+ assert_select "th", "One"
88
+ assert_select "th", "Two"
89
+ assert_select "th", "Three"
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ should "reset cycles for zebra_rows" do
97
+ show_view %(
98
+ <% recordset do %>
99
+ <% zebra_row do %>text<% end %>
100
+ <% end %>
101
+ <% recordset do %>
102
+ <% zebra_row do %>text<% end %>
103
+ <% end %>
104
+ ) do
105
+ assert_select "table.recordset" do
106
+ assert_select "tr.alt", 0
107
+ end
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
4
+ require 'active_support/test_case'
5
+
6
+ require 'shoulda/rails'
7
+ require 'action_controller'
8
+ require 'action_controller/test_process'
9
+
10
+ require "easel_helpers"
11
+
12
+ ActionView::Base.send :include, EaselHelpers::Helpers
13
+ ActionController::Base.send :include, EaselHelpers::PartialCaching
14
+
15
+ class EaselHelpers::ViewTestCase < ActiveSupport::TestCase
16
+ include ActionController::Assertions::SelectorAssertions
17
+
18
+ def setup
19
+ super
20
+ @view = ActionView::Base.new
21
+ end
22
+
23
+ protected
24
+
25
+ def show_view(template)
26
+ @html_result = ActionView::InlineTemplate.new(template).render(@view, {})
27
+ @html_document = HTML::Document.new(@html_result, true, false)
28
+ yield if block_given?
29
+ end
30
+
31
+ def response_from_page_or_rjs
32
+ @html_document.root
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fusionary-easel_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Clayton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-05 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: actionview
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ version:
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ type: :development
31
+ version_requirement:
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: "0"
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.1.0
40
+ version:
41
+ - !ruby/object:Gem::Dependency
42
+ name: hpricot
43
+ type: :development
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.8.1
53
+ version:
54
+ description: Fusionary Rails View Helpers
55
+ email: joshua.clayton@gmail.com
56
+ executables: []
57
+
58
+ extensions: []
59
+
60
+ extra_rdoc_files:
61
+ - lib/easel_helpers/helpers/date_helper.rb
62
+ - lib/easel_helpers/helpers/form_helper.rb
63
+ - lib/easel_helpers/helpers/grid_helper.rb
64
+ - lib/easel_helpers/helpers/link_helper.rb
65
+ - lib/easel_helpers/helpers/structure_helper.rb
66
+ - lib/easel_helpers/helpers/table_helper.rb
67
+ - lib/easel_helpers/helpers.rb
68
+ - lib/easel_helpers/rails_partial_caching.rb
69
+ - lib/easel_helpers.rb
70
+ - README.textile
71
+ - tasks/easel_helpers_tasks.rake
72
+ files:
73
+ - lib/easel_helpers/helpers/date_helper.rb
74
+ - lib/easel_helpers/helpers/form_helper.rb
75
+ - lib/easel_helpers/helpers/grid_helper.rb
76
+ - lib/easel_helpers/helpers/link_helper.rb
77
+ - lib/easel_helpers/helpers/structure_helper.rb
78
+ - lib/easel_helpers/helpers/table_helper.rb
79
+ - lib/easel_helpers/helpers.rb
80
+ - lib/easel_helpers/rails_partial_caching.rb
81
+ - lib/easel_helpers.rb
82
+ - Manifest
83
+ - MIT-LICENSE
84
+ - rails/init.rb
85
+ - Rakefile
86
+ - README.textile
87
+ - tasks/easel_helpers_tasks.rake
88
+ - easel_helpers.gemspec
89
+ - test/date_helper_test.rb
90
+ - test/form_helper_test.rb
91
+ - test/grid_helper_test.rb
92
+ - test/link_helper_test.rb
93
+ - test/structure_helper_test.rb
94
+ - test/table_helper_test.rb
95
+ - test/test_helper.rb
96
+ has_rdoc: true
97
+ homepage: http://github.com/fusionary/easel_helpers
98
+ post_install_message:
99
+ rdoc_options:
100
+ - --line-numbers
101
+ - --inline-source
102
+ - --title
103
+ - Easel_helpers
104
+ - --main
105
+ - README.textile
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ version:
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: "1.2"
119
+ version:
120
+ requirements: []
121
+
122
+ rubyforge_project: easel_helpers
123
+ rubygems_version: 1.2.0
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Fusionary Rails View Helpers
127
+ test_files:
128
+ - test/date_helper_test.rb
129
+ - test/form_helper_test.rb
130
+ - test/grid_helper_test.rb
131
+ - test/link_helper_test.rb
132
+ - test/structure_helper_test.rb
133
+ - test/table_helper_test.rb
134
+ - test/test_helper.rb