-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joshua Clayton
committed
May 1, 2009
1 parent
67c8e73
commit f08491f
Showing
9 changed files
with
156 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
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.rb | ||
Manifest | ||
MIT-LICENSE | ||
rails/init.rb | ||
Rakefile | ||
README.textile | ||
tasks/easel_helpers_tasks.rake | ||
test/easel_helpers_test.rb | ||
test/test_helper.rb | ||
Manifest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
module EaselHelpers | ||
module Helpers | ||
module DateHelper | ||
|
||
def datetime(dt = nil, default_text = "", format_string = :long) | ||
dt ? dt.to_time.to_s(format_string) : default_text | ||
end | ||
|
||
def date(dt = nil, default_text = "", format_string = :long) | ||
dt ? dt.to_date.to_s(format_string) : default_text | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
module EaselHelpers | ||
module Helpers | ||
module GridHelper | ||
MULTIPLES = { | ||
:one_twentyfourth => (1/24.to_f), | ||
:one_twelfth => (1/12.to_f), | ||
:one_eigth => (1/8.to_f), | ||
:one_sixth => (1/6.to_f), | ||
:five_twentyfourths => (5/24.to_f), | ||
:one_fourth => (1/4.to_f), | ||
:seven_twentyfourths => (7/24.to_f), | ||
:one_third => (1/3.to_f), | ||
:three_eigths => (3/8.to_f), | ||
:five_twelfths => (5/12.to_f), | ||
:eleven_twentyfourths => (11/24.to_f), | ||
:one_half => (1/2.to_f), | ||
:half => (1/2.to_f), | ||
:thirteen_twentyfourths => (13/24.to_f), | ||
:seven_twelfths => (7/12.to_f), | ||
:five_eigths => (5/8.to_f), | ||
:two_thirds => (2/3.to_f), | ||
:seventeen_twentyfourths => (17/24.to_f), | ||
:three_fourths => (3/4.to_f), | ||
:nineteen_twentyfourths => (19/24.to_f), | ||
:five_sixths => (5/6.to_f), | ||
:seven_eigths => (7/8.to_f), | ||
:eleven_twelfths => (11/12.to_f), | ||
:twentythree_twentyfourths => (23/24.to_f), | ||
:full => (1.to_f) | ||
}.freeze | ||
MULTIPLE_FRACTIONS = MULTIPLES.keys.map {|k| k.to_s }.freeze | ||
|
||
def column(size=nil, *args, &block) | ||
@_easel_column_count ||= application_width | ||
col(size, *args, &block) | ||
end | ||
|
||
def method_missing_with_easel_widths(call, *args) | ||
# filter out any initial helper calls | ||
found = false | ||
MULTIPLE_FRACTIONS.each do |w| | ||
found = true and break if call.to_s.include?(w) | ||
end | ||
method_missing_without_easel_widths(call, *args) and return unless found | ||
|
||
# one of the widths is somewhere in the helper call; let's find it | ||
call.to_s =~ /^((append|prepend|col)_)?(.+)$/ | ||
class_name = $2 || "col" | ||
class_width = $3 | ||
|
||
if MULTIPLES.keys.include?(class_width.to_sym) | ||
width = @_easel_column_count || application_width | ||
"#{class_name}-#{(width*MULTIPLES[class_width.to_sym]).to_i}" | ||
else | ||
method_missing_without_easel_widths(call, *args) | ||
end | ||
end | ||
|
||
alias_method_chain :method_missing, :easel_widths | ||
|
||
private | ||
|
||
def application_width; 24; end | ||
|
||
def increase_depth(size) | ||
@_easel_current_width = @_easel_column_count.to_s | ||
@_easel_column_count = size.to_s =~ /^\d+$/ ? size.to_s.to_i : (@_easel_column_count*MULTIPLES[size]).to_i | ||
end | ||
|
||
def decrease_depth(size) | ||
@_easel_column_count = size.is_a?(Integer) ? @_easel_current_width.to_i : (@_easel_column_count/MULTIPLES[size]).to_i | ||
@_easel_current_width = nil | ||
end | ||
|
||
def col(size=nil, *args, &block) | ||
size = :full if size.blank? | ||
|
||
increase_depth(size) | ||
output_tag = generate_output_tag(size, args, &block) | ||
|
||
if block_given? && block_is_within_action_view?(block) | ||
concat(output_tag) | ||
decrease_depth(size) | ||
else | ||
decrease_depth(size) | ||
output_tag | ||
end | ||
end | ||
|
||
def generate_output_tag(size, *args, &block) | ||
options = args.extract_options! | ||
|
||
css_classes = [] << options.delete(:class) << args | ||
css_classes << "col-#{@_easel_column_count}" unless options.delete(:suppress_col) | ||
css_classes << "col-last" if size.to_sym == :full && @_easel_column_count != application_width | ||
|
||
content_tag(:div, capture(&block), {:class => clean_css_classes(css_classes, {"last" => "col-last"})}.merge(options)) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
module EaselHelpers | ||
module Helpers | ||
module LinkHelper | ||
|
||
def link_button(*args, &block) | ||
doc = Hpricot(link_to(*args, &block)) | ||
doc.at("a").inner_html = "<span>#{doc.at("a").inner_html}</span>" | ||
(doc/:a).add_class("btn") | ||
doc.to_html | ||
end | ||
|
||
def link_to_email(email_address, *args) | ||
options = args.extract_options! | ||
link = args.first.is_a?(String) ? h(args.first) : email_address | ||
return link if email_address.blank? | ||
link_to link, "mailto:#{email_address}", options | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters