storefront 0.3.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -4
- data/lib/storefront.rb +22 -35
- data/lib/storefront/components/base.rb +99 -0
- data/lib/storefront/components/breadcrumb.rb +7 -0
- data/lib/storefront/components/button.rb +37 -0
- data/lib/storefront/components/definition_list.rb +34 -0
- data/lib/storefront/components/definition_list_item.rb +63 -0
- data/lib/storefront/components/flash.rb +12 -0
- data/lib/storefront/components/footer.rb +19 -0
- data/lib/storefront/components/form.rb +82 -0
- data/lib/storefront/{form → components/form}/base.rb +3 -3
- data/lib/storefront/{form → components/form}/builder.rb +3 -3
- data/lib/storefront/{form → components/form}/errors.rb +1 -3
- data/lib/storefront/{form → components/form}/field.rb +1 -1
- data/lib/storefront/{form → components/form}/fieldset.rb +0 -0
- data/lib/storefront/{form → components/form}/hint.rb +0 -0
- data/lib/storefront/{form → components/form}/input.rb +7 -5
- data/lib/storefront/components/form/inputs.rb +7 -0
- data/lib/storefront/{form → components/form}/inputs/checkbox.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/date.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/file.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/hidden.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/radio.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/range.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/select.rb +6 -6
- data/lib/storefront/{form → components/form}/inputs/string.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/submit.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/textarea.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/value.rb +0 -0
- data/lib/storefront/{form → components/form}/label.rb +1 -1
- data/lib/storefront/components/header.rb +73 -0
- data/lib/storefront/components/image.rb +12 -0
- data/lib/storefront/components/javascript_template.rb +21 -0
- data/lib/storefront/components/list.rb +27 -0
- data/lib/storefront/components/menu.rb +41 -0
- data/lib/storefront/components/nav.rb +78 -0
- data/lib/storefront/components/sidebar.rb +23 -0
- data/lib/storefront/components/table.rb +232 -0
- data/lib/storefront/components/text.rb +29 -0
- data/lib/storefront/configuration.rb +53 -5
- data/lib/storefront/helpers/cache_helper.rb +37 -19
- data/lib/storefront/helpers/component_helper.rb +80 -41
- data/lib/storefront/helpers/content_helper.rb +211 -0
- data/lib/storefront/helpers/dom_helper.rb +136 -0
- data/lib/storefront/helpers/head_helper.rb +277 -205
- data/lib/storefront/helpers/model_helper.rb +21 -0
- data/lib/storefront/helpers/request_helper.rb +301 -53
- data/lib/storefront/helpers/tag_helper.rb +29 -0
- data/lib/storefront/{proxies/attribute_proxy.rb → models/attribute.rb} +1 -1
- data/lib/storefront/{proxies/model_proxy.rb → models/model.rb} +4 -6
- data/lib/storefront/railtie.rb +3 -16
- metadata +48 -64
- data/lib/storefront/dashboard.rb +0 -185
- data/lib/storefront/form.rb +0 -82
- data/lib/storefront/helpers/attribute_helper.rb +0 -81
- data/lib/storefront/helpers/body_helper.rb +0 -18
- data/lib/storefront/helpers/browser_helper.rb +0 -54
- data/lib/storefront/helpers/collection_helper.rb +0 -14
- data/lib/storefront/helpers/dashboard_helper.rb +0 -29
- data/lib/storefront/helpers/debug_helper.rb +0 -11
- data/lib/storefront/helpers/definition_list_helper.rb +0 -110
- data/lib/storefront/helpers/error_helper.rb +0 -11
- data/lib/storefront/helpers/flash_helper.rb +0 -14
- data/lib/storefront/helpers/form_helper.rb +0 -13
- data/lib/storefront/helpers/format_helper.rb +0 -59
- data/lib/storefront/helpers/image_helper.rb +0 -30
- data/lib/storefront/helpers/list_helper.rb +0 -135
- data/lib/storefront/helpers/locale_helper.rb +0 -245
- data/lib/storefront/helpers/open_graph_helper.rb +0 -5
- data/lib/storefront/helpers/page_helper.rb +0 -91
- data/lib/storefront/helpers/presenter_helper.rb +0 -5
- data/lib/storefront/helpers/semantic/location_helper.rb +0 -18
- data/lib/storefront/helpers/semantic/time_helper.rb +0 -14
- data/lib/storefront/helpers/sidebar_helper.rb +0 -27
- data/lib/storefront/helpers/system_helper.rb +0 -18
- data/lib/storefront/helpers/table_helper.rb +0 -38
- data/lib/storefront/helpers/template_helper.rb +0 -11
- data/lib/storefront/helpers/time_helper.rb +0 -21
- data/lib/storefront/helpers/url_helper.rb +0 -32
- data/lib/storefront/helpers/user_helper.rb +0 -15
- data/lib/storefront/helpers/widget_helper.rb +0 -142
- data/lib/storefront/helpers/workflow_helper.rb +0 -50
- data/lib/storefront/model_helper.rb +0 -17
- data/lib/storefront/table.rb +0 -198
- data/rails/init.rb +0 -1
- data/test/form_helper_test.rb +0 -5
- data/test/support/mock_controller.rb +0 -15
- data/test/support/mock_response.rb +0 -14
- data/test/support/models.rb +0 -0
- data/test/test_helper.rb +0 -34
@@ -1,18 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module Semantic
|
3
|
-
module LocationHelper
|
4
|
-
def semantic_geo_tag(lat, lng, options = {})
|
5
|
-
capture_haml do
|
6
|
-
haml_tag :span, :itemprop => "geo", :itemtype => "http://data-vocabulary.org/Geo" do
|
7
|
-
haml_tag :span, :itemprop => "latitude" do
|
8
|
-
haml_tag :span, lat, :class => "value-title"
|
9
|
-
end
|
10
|
-
haml_tag :span, :itemprop => "longitude" do
|
11
|
-
haml_tag :span, lng, :class => "value-title"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module Semantic
|
3
|
-
module TimeHelper
|
4
|
-
def semantic_time_tag(value, time, options = {})
|
5
|
-
capture_haml do
|
6
|
-
haml_tag :time, :class => "dtstart", :itemprop => "startDate", :title => time.xmlschema, :datetime => time.xmlschema do
|
7
|
-
haml_tag :span, :class => "value-title", :title => time.xmlschema
|
8
|
-
haml_concat value
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module SidebarHelper
|
3
|
-
def sidebar_for(record, options = {}, &block)
|
4
|
-
@sidebar_record = record
|
5
|
-
concat(capture(&block))
|
6
|
-
@sidebar_record = nil
|
7
|
-
end
|
8
|
-
|
9
|
-
def sidebar(*args)
|
10
|
-
locals = args.extract_options!
|
11
|
-
path = args.shift
|
12
|
-
if path.blank?
|
13
|
-
path = resource.class.name.underscore.pluralize.to_sym rescue nil
|
14
|
-
end
|
15
|
-
if path.is_a?(Symbol)
|
16
|
-
path = [path_namespace, path.to_s, "sidebar"].compact.join("/")
|
17
|
-
end
|
18
|
-
content_for :sidebar do
|
19
|
-
render :partial => path, :locals => locals
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def sidebar_record
|
24
|
-
@sidebar_record
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module SystemHelper
|
3
|
-
def windows?
|
4
|
-
# Can't match for just 'win' cause it will match darwin as well.
|
5
|
-
(/win32|mswin|mingw/).match(RUBY_PLATFORM) ? true : false
|
6
|
-
end
|
7
|
-
|
8
|
-
# Works on Debian and Ubuntu, don't have anything else to test on.
|
9
|
-
def linux?
|
10
|
-
(/linux/).match(RUBY_PLATFORM) ? true : false
|
11
|
-
end
|
12
|
-
|
13
|
-
# Works on my MacBook Pro, don't have anything else to test on,
|
14
|
-
def mac?
|
15
|
-
(/darwin/).match(RUBY_PLATFORM) ? true : false
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module TableHelper
|
3
|
-
def table_for(*args, &block)
|
4
|
-
Storefront::Table.new(self, *args, &block).content
|
5
|
-
end
|
6
|
-
|
7
|
-
def table_query_row_class
|
8
|
-
["search-row", query_params.except("page", "sort").blank? ? nil : "search-results"].compact.join(" ")
|
9
|
-
end
|
10
|
-
|
11
|
-
def link_to_sort(title, attribute, options = {})
|
12
|
-
sort_param = sort_value(attribute, opposite_sort_direction(attribute))
|
13
|
-
link_to title, with_params(request.path, :sort => sort_param), options
|
14
|
-
end
|
15
|
-
|
16
|
-
def next_page_path(collection)
|
17
|
-
with_params(request.path, :page => collection.next_page)
|
18
|
-
end
|
19
|
-
|
20
|
-
def prev_page_path(collection)
|
21
|
-
with_params(request.path, :page => collection.prev_page)
|
22
|
-
end
|
23
|
-
|
24
|
-
def first_page_path(collection)
|
25
|
-
with_params(request.path, :page => 1)
|
26
|
-
end
|
27
|
-
|
28
|
-
def last_page_path(collection)
|
29
|
-
with_params(request.path, :page => collection.last_page)
|
30
|
-
end
|
31
|
-
|
32
|
-
def current_page_num
|
33
|
-
page = params[:page] ? params[:page].to_i : 1
|
34
|
-
page = 1 if page < 1
|
35
|
-
page
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module TemplateHelper
|
3
|
-
def javascript_template(name, options = {}, &block)
|
4
|
-
options[:id] ||= name.to_s.strip.gsub(/[\s|_]+/, storefront_config.separator).squeeze(storefront_config.separator)
|
5
|
-
options[:type] ||= "text/html"
|
6
|
-
capture_haml do
|
7
|
-
haml_tag :script, options, &block
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module TimeHelper
|
3
|
-
# (new Date()).getTimezoneOffset() in JavaScript returns (UTC - localtime) in
|
4
|
-
# minutes, while ActiveSupport::TimeZone expects (localtime - UTC) in seconds.
|
5
|
-
def set_time_zone
|
6
|
-
offset = (cookies[:timezone] || 0).to_i * -60
|
7
|
-
# User.time_zone = ActiveSupport::TimeZone[-min.minutes]
|
8
|
-
::User.time_zone = ActiveSupport::TimeZone.us_zones.find { |z| z.utc_offset == offset.to_i }
|
9
|
-
true
|
10
|
-
end
|
11
|
-
|
12
|
-
def record_post_time
|
13
|
-
cookies[:last_post_at] = Time.zone.now.to_i
|
14
|
-
end
|
15
|
-
|
16
|
-
def html5_time(date_or_time)
|
17
|
-
return nil if date_or_time.blank?
|
18
|
-
date_or_time.acts_like?(:time) ? date_or_time.xmlschema : date_or_time.rfc3339
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module UrlHelper
|
3
|
-
def current_subdomain
|
4
|
-
subdomain = request.subdomain.to_s.split(".").first
|
5
|
-
subdomain = nil if subdomain == App.name
|
6
|
-
(subdomain.blank? || subdomain == "www") ? nil : subdomain
|
7
|
-
end
|
8
|
-
|
9
|
-
def path_namespace?(*args)
|
10
|
-
args.present? ? args.any? { |is| path_namespace == is.to_s } : path_namespace.present?
|
11
|
-
end
|
12
|
-
|
13
|
-
def path_namespace
|
14
|
-
if @path_namespace.nil?
|
15
|
-
if current_subdomain.present?
|
16
|
-
@path_namespace = current_subdomain
|
17
|
-
elsif params[:path_namespace]
|
18
|
-
@path_namespace = params[:path_namespace]
|
19
|
-
else
|
20
|
-
parts = params[:controller].split("/")
|
21
|
-
@path_namespace = parts.length > 1 ? parts.first : ""
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
@path_namespace
|
26
|
-
end
|
27
|
-
|
28
|
-
def with_current_params(path_method, *args)
|
29
|
-
send path_method, *(args << Rack::Utils.parse_query(request.query_string).merge(args.extract_options!))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module UserHelper
|
3
|
-
def globalize_current_user
|
4
|
-
current_user.request = request if current_user
|
5
|
-
User.current = current_user
|
6
|
-
Rails.logger.info "Current User: [#{ip_address}] #{current_user.present? ? current_user.email : 'Unknown'} (#{user_agent})"
|
7
|
-
true
|
8
|
-
end
|
9
|
-
|
10
|
-
def deglobalize_current_user
|
11
|
-
User.current = nil
|
12
|
-
true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,142 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module WidgetHelper
|
3
|
-
def widget(*args, &block)
|
4
|
-
options = args.extract_options!
|
5
|
-
path = args.shift
|
6
|
-
name = path.to_s.gsub("/", "_")
|
7
|
-
|
8
|
-
if self.respond_to?("#{name}_widget")
|
9
|
-
send("#{name}_widget", name, options, &block)
|
10
|
-
else
|
11
|
-
raise "Please define a helper method 'def #{name}_widget(*args)'"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def text_widget(*args, &block)
|
16
|
-
options = text_widget_options(*args)
|
17
|
-
|
18
|
-
capture_haml do
|
19
|
-
haml_tag :article, options[:outer_html] do
|
20
|
-
header = header_widget(options)
|
21
|
-
haml_concat header if header.present?
|
22
|
-
content = options[:content]
|
23
|
-
content ||= capture(&block) if block_given?
|
24
|
-
haml_tag options[:tag], content, options[:content_html]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def text_widget_options(*args)
|
30
|
-
options = widget_options(*args)
|
31
|
-
|
32
|
-
options[:content_html] ||= {}
|
33
|
-
|
34
|
-
merge_class! options, storefront_config.content_class
|
35
|
-
|
36
|
-
options[:tag] ||= :p
|
37
|
-
|
38
|
-
options
|
39
|
-
end
|
40
|
-
|
41
|
-
def buttons_widget(*args, &block)
|
42
|
-
options = args.extract_options!
|
43
|
-
options = widget_options("buttons-widget", options.reverse_merge(:title => false))
|
44
|
-
|
45
|
-
capture_haml do
|
46
|
-
haml_tag :nav, options[:outer_html], &block
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def footer_widget(*args, &block)
|
51
|
-
options = args.extract_options!
|
52
|
-
options = widget_options("footer-widget", options.reverse_merge(:title => false))
|
53
|
-
|
54
|
-
capture_haml do
|
55
|
-
haml_tag :footer, options[:outer_html], &block
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def header_widget(options = {}, &block)
|
60
|
-
options = header_widget_options(options) unless options[:skip_format]
|
61
|
-
|
62
|
-
return nil if options.blank?
|
63
|
-
|
64
|
-
capture_haml do
|
65
|
-
if block_given?
|
66
|
-
haml_tag :header, options[:header_html], &block
|
67
|
-
else
|
68
|
-
level = options[:level] || 3
|
69
|
-
title = options[:title_html].delete(:value)
|
70
|
-
subtitle = options[:subtitle_html].delete(:value)
|
71
|
-
|
72
|
-
haml_tag :header, options[:header_html] do
|
73
|
-
if subtitle.present?
|
74
|
-
haml_tag :hgroup do
|
75
|
-
haml_tag :"h#{level}", title, options[:title_html]
|
76
|
-
haml_tag :"h#{level + 1}", subtitle, options[:subtitle_html]
|
77
|
-
end
|
78
|
-
else
|
79
|
-
haml_tag :"h#{level}", title, options[:title_html]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def header_widget_options(options = {})
|
87
|
-
return {} if options[:title] == false
|
88
|
-
|
89
|
-
header_html = options[:header_html] || {}
|
90
|
-
header_html.reverse_merge!(:class => storefront_config.header_class)
|
91
|
-
|
92
|
-
title_html = options[:title_html] || {}
|
93
|
-
title_html.reverse_merge!(:class => storefront_config.title_class)
|
94
|
-
title_html[:value] = options.delete(:title)
|
95
|
-
|
96
|
-
title_html[:value] = t?(title_html[:value], :scope => :"widgets.headers") if title_html[:value].is_a?(::Symbol)
|
97
|
-
|
98
|
-
subtitle_html = options[:subtitle_html] || {}
|
99
|
-
if subtitle_html.present? || options[:subtitle].present?
|
100
|
-
subtitle_html.reverse_merge!(:class => storefront_config.subtitle_class)
|
101
|
-
subtitle_html[:value] = options.delete(:subtitle)
|
102
|
-
subtitle_html[:value] = t?(subtitle_html[:value], :scope => :"widgets.headers") if subtitle_html[:value].is_a?(::Symbol)
|
103
|
-
end
|
104
|
-
|
105
|
-
options.merge! :header_html => header_html, :title_html => title_html, :subtitle_html => subtitle_html
|
106
|
-
|
107
|
-
options
|
108
|
-
end
|
109
|
-
|
110
|
-
protected
|
111
|
-
def render_widget_partial(name, *args)
|
112
|
-
path = name.is_a?(::Symbol) ? ::File.join(storefront_config.widgets_path, name.to_s) : name.to_s
|
113
|
-
locals = args.extract_options!.merge(:yielded_content => block_given? ? capture(&block) : nil)
|
114
|
-
render :partial => path, :locals => locals
|
115
|
-
end
|
116
|
-
|
117
|
-
def widget_options(type, *args)
|
118
|
-
options = args.extract_options!
|
119
|
-
key = args.shift
|
120
|
-
|
121
|
-
options[:title] ||= false
|
122
|
-
options[:key] ||= key
|
123
|
-
options[:outer_html] ||= {}
|
124
|
-
|
125
|
-
options[:body_html] ||= {}
|
126
|
-
options[:footer_html] ||= {}
|
127
|
-
|
128
|
-
unless options[:widget_class] == false
|
129
|
-
merge_class! options[:outer_html], *widget_classes(type)
|
130
|
-
end
|
131
|
-
|
132
|
-
options
|
133
|
-
end
|
134
|
-
|
135
|
-
def widget_classes(type)
|
136
|
-
[
|
137
|
-
storefront_config.widget_class,
|
138
|
-
type.to_s.strip.gsub(/[\s|_]+/, storefront_config.separator).squeeze(storefront_config.separator)
|
139
|
-
]
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module WorkflowHelper
|
3
|
-
def current_workflow
|
4
|
-
params[:flow]
|
5
|
-
end
|
6
|
-
|
7
|
-
def flow?(*args)
|
8
|
-
args.present? ? args.any? { |flow| current_workflow == flow.to_s } : current_workflow.present?
|
9
|
-
end
|
10
|
-
|
11
|
-
def workflow_steps(current, *labels)
|
12
|
-
steps = labels.flatten.map do |label|
|
13
|
-
if label.is_a?(Hash)
|
14
|
-
label.symbolize_keys
|
15
|
-
else
|
16
|
-
{:title => label, :description => ""}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
steps.each_with_index do |step, index|
|
20
|
-
step[:active] = index == (current - 1)
|
21
|
-
end
|
22
|
-
steps
|
23
|
-
end
|
24
|
-
|
25
|
-
def workflow_step(label, current, desired)
|
26
|
-
image_name = "step_#{desired}"
|
27
|
-
image_name << "_active" if current == desired
|
28
|
-
image_name << ".png"
|
29
|
-
td_class = current == desired ? "step_active" : "step"
|
30
|
-
result = capture_haml do
|
31
|
-
haml_tag :td, :class => :number do
|
32
|
-
haml_tag :img, :class => :step_number, :src => "/images/#{image_name}"
|
33
|
-
end
|
34
|
-
haml_tag :td, :class => td_class do
|
35
|
-
haml_concat label
|
36
|
-
end
|
37
|
-
end
|
38
|
-
result
|
39
|
-
end
|
40
|
-
|
41
|
-
def next_step_tag(resource = self.resource)
|
42
|
-
result = capture_haml do
|
43
|
-
haml_concat hidden_field_tag(:event, current_step)
|
44
|
-
if resource && resource.id
|
45
|
-
haml_concat hidden_field_tag(:id, resource.id)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
module ModelHelper
|
3
|
-
def self.included(base)
|
4
|
-
base.class_eval do
|
5
|
-
def self.to_title
|
6
|
-
name
|
7
|
-
end unless self.respond_to?(:to_title)
|
8
|
-
|
9
|
-
def to_title
|
10
|
-
return title if respond_to?(:title)
|
11
|
-
return name if respond_to?(:name)
|
12
|
-
to_s
|
13
|
-
end unless self.instance_methods.include?(:to_title)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/storefront/table.rb
DELETED
@@ -1,198 +0,0 @@
|
|
1
|
-
module Storefront
|
2
|
-
class Table
|
3
|
-
include Storefront::AttributeHelper
|
4
|
-
include Storefront::LocaleHelper
|
5
|
-
include Storefront::TimeHelper
|
6
|
-
|
7
|
-
attr_reader :content, :template, :key
|
8
|
-
|
9
|
-
def initialize(template, *args, &block)
|
10
|
-
@template = template
|
11
|
-
options = args.extract_options!
|
12
|
-
record_or_key = args.shift
|
13
|
-
@key = record_key(record_or_key)
|
14
|
-
@row_index = 0
|
15
|
-
@cell_index = 0
|
16
|
-
@scope = :table
|
17
|
-
@headers = []
|
18
|
-
options[:summary] ||= "Table for #{key.titleize}"
|
19
|
-
options[:class] = ["data-table", options[:class]].compact.uniq.join(" ")
|
20
|
-
options[:role] = :grid
|
21
|
-
data = options.delete(:data) || {}
|
22
|
-
data[:url] = options[:url] || @template.controller.request.path
|
23
|
-
data[:for] = options[:for] || options[:model] || @key
|
24
|
-
data[:total] = options[:total] if options[:total]
|
25
|
-
data[:page] = options[:page] if options[:page]
|
26
|
-
data[:count] = options[:count] if options[:count]
|
27
|
-
aria = options.delete(:aria) || {}
|
28
|
-
aria[:"aria-multiselectable"] = false unless aria.has_key?(:"aria-multiselectable") || options[:multiselect] == true
|
29
|
-
options[:data] = data
|
30
|
-
options[:id] ||= "#{record_or_key.to_s}-table"
|
31
|
-
|
32
|
-
@content = template.capture_haml do
|
33
|
-
template.haml_tag :table, options do
|
34
|
-
yield(self)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def caption
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
# scope='col'
|
44
|
-
def head(attributes = {}, &block)
|
45
|
-
@hide_header = attributes.delete(:visible) == false
|
46
|
-
template.capture_haml do
|
47
|
-
@row_index = 0
|
48
|
-
@scope = :head
|
49
|
-
template.haml_tag :thead, attributes, &block
|
50
|
-
@row_index = 0
|
51
|
-
@scope = :table
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# scope='row'
|
56
|
-
# <td headers='x'/>
|
57
|
-
def body(attributes = {}, &block)
|
58
|
-
template.capture_haml do
|
59
|
-
@row_index = 0
|
60
|
-
@scope = :body
|
61
|
-
template.haml_tag :tbody, attributes, &block
|
62
|
-
@row_index = 0
|
63
|
-
@scope = :table
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def foot(attributes = {}, &block)
|
68
|
-
template.capture_haml do
|
69
|
-
@row_index = 0
|
70
|
-
@scope = :foot
|
71
|
-
template.haml_tag :tfoot, attributes, &block
|
72
|
-
@row_index = 0
|
73
|
-
@scope = :table
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def row(*args, &block)
|
78
|
-
attributes = args.extract_options!
|
79
|
-
if @scope == :body
|
80
|
-
attributes[:class] = [template.cycle("odd", "even"), attributes[:class]].compact.uniq.join(" ")
|
81
|
-
end
|
82
|
-
attributes[:role] = :row
|
83
|
-
attributes[:scope] = :row
|
84
|
-
template.capture_haml do
|
85
|
-
@row_index += 1
|
86
|
-
@cell_index = 0
|
87
|
-
template.haml_tag :tr, attributes, &block
|
88
|
-
@cell_index = 0
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def column(*args, &block)
|
93
|
-
attributes = args.extract_options!
|
94
|
-
value = args.shift
|
95
|
-
attributes[:id] ||= id_for(:header, key, value, @row_index, @cell_index)
|
96
|
-
[:width, :height].each do |size|
|
97
|
-
attributes[size] = pixelate(attributes[size]) unless attributes[size].nil?
|
98
|
-
end
|
99
|
-
@headers.push(attributes[:id])
|
100
|
-
|
101
|
-
template.capture_haml do
|
102
|
-
template.haml_tag :col, attributes
|
103
|
-
@cell_index += 1
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# direction => "ascending"
|
108
|
-
# valid directions: ascending, descending, none, other
|
109
|
-
# abbr is what the header controls (for sorting)
|
110
|
-
def header(*args, &block)
|
111
|
-
attributes = args.extract_options!
|
112
|
-
value = args.shift
|
113
|
-
if value.is_a?(::Symbol)
|
114
|
-
attributes[:abbr] ||= value.to_s
|
115
|
-
end
|
116
|
-
# aria-selected if sorted
|
117
|
-
attributes[:role] = :columnheader
|
118
|
-
attributes[:id] ||= id_for(:header, key, value, @row_index, @cell_index)
|
119
|
-
attributes[:scope] = :col
|
120
|
-
attributes[:abbr] ||= attributes.delete(:for) if attributes.has_key?(:for)
|
121
|
-
[:width, :height].each do |size|
|
122
|
-
attributes[size] = pixelate(attributes[size]) unless attributes[size].nil?
|
123
|
-
end
|
124
|
-
sort = attributes.delete(:sort) == true
|
125
|
-
label = attributes.delete(:label) || (value.is_a?(::String) ? value.strip : value.to_s.titleize)
|
126
|
-
|
127
|
-
if sort
|
128
|
-
attributes[:class] = [attributes[:class], attributes.delete(:sort_class) || "sortable"].compact.uniq.join(" ")
|
129
|
-
attributes[:direction] ||= template.sort_class(value)
|
130
|
-
end
|
131
|
-
|
132
|
-
direction = attributes.delete(:direction)
|
133
|
-
if direction.present?
|
134
|
-
attributes[:"aria-sort"] = direction
|
135
|
-
attributes[:class] = [attributes[:class], direction].join(" ")
|
136
|
-
attributes[:"aria-selected"] = true
|
137
|
-
else
|
138
|
-
attributes[:"aria-sort"] = "none"
|
139
|
-
attributes[:"aria-selected"] = false
|
140
|
-
end
|
141
|
-
|
142
|
-
@headers.push(attributes[:id])
|
143
|
-
template.capture_haml do
|
144
|
-
if block_given?
|
145
|
-
template.haml_tag :th, attributes, &block
|
146
|
-
else
|
147
|
-
if sort
|
148
|
-
template.haml_tag :th, attributes do
|
149
|
-
template.haml_concat template.link_to_sort(label, value)
|
150
|
-
end
|
151
|
-
else
|
152
|
-
template.haml_tag :th, label, attributes
|
153
|
-
end
|
154
|
-
end
|
155
|
-
@cell_index += 1
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
def cell(*args, &block)
|
160
|
-
attributes = args.extract_options!
|
161
|
-
value = args.shift
|
162
|
-
attributes[:role] = :gridcell
|
163
|
-
attributes[:id] ||= id_for(:cell, key, value, @row_index, @cell_index)
|
164
|
-
#attributes[:"aria-describedby"] = @headers[@cell_index]
|
165
|
-
attributes[:headers] = @headers[@cell_index]
|
166
|
-
[:width, :height].each do |size|
|
167
|
-
attributes[size] = pixelate(attributes[size]) unless attributes[size].nil?
|
168
|
-
end
|
169
|
-
template.capture_haml do
|
170
|
-
if block_given?
|
171
|
-
template.haml_tag :td, attributes, &block
|
172
|
-
else
|
173
|
-
template.haml_tag :td, value.to_s.strip, attributes
|
174
|
-
end
|
175
|
-
@cell_index += 1
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def record_key(record_or_key)
|
180
|
-
if record_or_key.is_a?(String) || record_or_key.is_a?(Symbol)
|
181
|
-
record_or_key.to_s
|
182
|
-
else
|
183
|
-
record_or_key.class.name
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
def id_for(type, key, value, row_index = @row_index, column_index = @column_index)
|
188
|
-
[key, type, row_index, column_index].compact.map do |node|
|
189
|
-
node.to_s.gsub(/[\s_]/, "-")
|
190
|
-
end.join("-")
|
191
|
-
end
|
192
|
-
|
193
|
-
private
|
194
|
-
def pixelate(value)
|
195
|
-
value.is_a?(::String) ? value : "#{value}px"
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|