storefront 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,81 +0,0 @@
|
|
|
1
|
-
module Storefront
|
|
2
|
-
module AttributeHelper
|
|
3
|
-
def clone_attributes(hash)
|
|
4
|
-
result = {}
|
|
5
|
-
return result if hash.blank?
|
|
6
|
-
hash.each do |key, value|
|
|
7
|
-
result[key] = value.is_a?(::Hash) ? clone_attributes(value) : value
|
|
8
|
-
end
|
|
9
|
-
result
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def storefront_config
|
|
13
|
-
Storefront.configuration
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def underscore_class_name(record)
|
|
17
|
-
record.class.base_class.snake_case
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def datetime_for(time)
|
|
21
|
-
with_time_at time
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def record_method(method, *args, &block)
|
|
25
|
-
record = args.shift
|
|
26
|
-
sent_method = "#{method}_for_#{underscore_class_name(record)}"
|
|
27
|
-
if args.length > 0 && options = args.pop
|
|
28
|
-
if !respond_to?(sent_method) && record.respond_to?(:presenter) && record.presenter.present? && record.presenter.respond_to?(method)
|
|
29
|
-
record.presenter.send(method, options)
|
|
30
|
-
else
|
|
31
|
-
send(sent_method, record, options, &block)
|
|
32
|
-
end
|
|
33
|
-
else
|
|
34
|
-
if !respond_to?(sent_method) && record.respond_to?(:presenter) && record.presenter.present? && record.presenter.respond_to?(method)
|
|
35
|
-
record.presenter.send(method)
|
|
36
|
-
else
|
|
37
|
-
send(sent_method, record, &block)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def merge_class!(attributes, *values)
|
|
43
|
-
return {} if attributes.nil?
|
|
44
|
-
hash = merge_class(attributes, *values)
|
|
45
|
-
attributes[:class] = hash[:class] if hash
|
|
46
|
-
attributes
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def merge_class(attributes, *values)
|
|
50
|
-
if values.present?
|
|
51
|
-
if attributes[:class].present?
|
|
52
|
-
classes = attributes[:class].split(/\s+/)
|
|
53
|
-
else
|
|
54
|
-
classes = []
|
|
55
|
-
end
|
|
56
|
-
classes += values.compact.map(&:to_s)
|
|
57
|
-
classes.uniq!
|
|
58
|
-
else
|
|
59
|
-
classes = nil
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
if classes.present?
|
|
63
|
-
attributes.merge(:class => classes.join(" "))
|
|
64
|
-
else
|
|
65
|
-
attributes
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def index_class(index, length)
|
|
70
|
-
return nil if length.blank? || (length <= 1)
|
|
71
|
-
|
|
72
|
-
if index == 0
|
|
73
|
-
"first"
|
|
74
|
-
elsif index == length - 1
|
|
75
|
-
"last"
|
|
76
|
-
else
|
|
77
|
-
nil
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module Storefront
|
|
2
|
-
module BodyHelper
|
|
3
|
-
def body_id(string)
|
|
4
|
-
@body_id = string
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def body_class(string)
|
|
8
|
-
@body_class = string
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def body_attributes(options = {})
|
|
12
|
-
options[:class] = @body_class if @body_class
|
|
13
|
-
options[:id] = @body_id if @body_id
|
|
14
|
-
|
|
15
|
-
options
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
module Storefront
|
|
2
|
-
module BrowserHelper
|
|
3
|
-
# check the current browser (via user agent) for the following:
|
|
4
|
-
# :mozilla / :firefox
|
|
5
|
-
# :ie6
|
|
6
|
-
# :ie7
|
|
7
|
-
# :ie
|
|
8
|
-
# :iphone
|
|
9
|
-
# :safari
|
|
10
|
-
def browser_is? name
|
|
11
|
-
name = name.to_s.strip
|
|
12
|
-
|
|
13
|
-
return true if browser_name == name
|
|
14
|
-
return true if (name == 'mozilla' or name == "firefox") && browser_name == 'gecko'
|
|
15
|
-
return true if name == 'ie6' && browser_name.index('ie6')
|
|
16
|
-
return true if name == 'ie7' && browser_name.index('ie7')
|
|
17
|
-
return true if name == 'ie' && browser_name.index('ie')
|
|
18
|
-
return true if name == 'iphone' && browser_name == 'iphone'
|
|
19
|
-
return true if name == 'webkit' && browser_name == 'safari'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# find the current browser name
|
|
23
|
-
def browser_name
|
|
24
|
-
@browser_name ||= begin
|
|
25
|
-
ua = request.user_agent.to_s.downcase
|
|
26
|
-
if ua.index('msie') && !ua.index('opera') && !ua.index('webtv')
|
|
27
|
-
'ie'+ua[ua.index('msie')+5].chr
|
|
28
|
-
elsif ua.index('gecko/')
|
|
29
|
-
'gecko'
|
|
30
|
-
elsif ua.index('opera')
|
|
31
|
-
'opera'
|
|
32
|
-
elsif ua.index('konqueror')
|
|
33
|
-
'konqueror'
|
|
34
|
-
elsif ua.index('iphone')
|
|
35
|
-
'iphone'
|
|
36
|
-
elsif ua.index('applewebkit/')
|
|
37
|
-
'safari'
|
|
38
|
-
elsif ua.index('mozilla/')
|
|
39
|
-
'gecko'
|
|
40
|
-
else
|
|
41
|
-
""
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def ip_address
|
|
47
|
-
request.env['REMOTE_ADDR']
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def user_agent
|
|
51
|
-
request.user_agent
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module Storefront
|
|
2
|
-
module DashboardHelper
|
|
3
|
-
def dashboard_for(*args, &block)
|
|
4
|
-
record = args.shift
|
|
5
|
-
options = args.extract_options!
|
|
6
|
-
@dashboard_record = record
|
|
7
|
-
concat(capture(&block)) if record
|
|
8
|
-
@dashboard_record = nil
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def figure(*names, &block)
|
|
12
|
-
locals = names.extract_options!
|
|
13
|
-
|
|
14
|
-
locals.reverse_merge(:locale => nil)
|
|
15
|
-
locals.merge!(:yielded_content => capture(&block)) if block_given?
|
|
16
|
-
result = capture_haml do
|
|
17
|
-
names.each do |name|
|
|
18
|
-
haml_concat render(:partial => "shared/dashboard/#{name}", :locals => locals)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
result
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def report_for(record_or_key, hash, options = {}, &block)
|
|
26
|
-
Storefront::Dashboard.new(self, record_or_key, hash, options, &block).content
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
module Storefront
|
|
2
|
-
module DefinitionListHelper
|
|
3
|
-
def definition_list_widget(*args, &block)
|
|
4
|
-
options = definition_list_widget_options(*args)
|
|
5
|
-
|
|
6
|
-
capture_haml do
|
|
7
|
-
haml_tag options[:as], options[:outer_html] do
|
|
8
|
-
@separator = options.has_key?(:separator) ? options[:separator] : storefront_config.term_separator
|
|
9
|
-
header = header_widget(options)
|
|
10
|
-
haml_concat header.gsub(/\n$/, "") if header.present?
|
|
11
|
-
|
|
12
|
-
haml_tag options[:tag], options[:content_html], &block
|
|
13
|
-
|
|
14
|
-
if options[:footer_html].present?
|
|
15
|
-
haml_concat footer_widget(options[:footer_html])
|
|
16
|
-
end
|
|
17
|
-
@separator = nil
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
alias terms_widget definition_list_widget
|
|
22
|
-
|
|
23
|
-
def definition_list_widget_options(*args)
|
|
24
|
-
options = widget_options("definition-list-widget", *args)
|
|
25
|
-
|
|
26
|
-
options[:as] ||= :section
|
|
27
|
-
options[:tag] ||= storefront_config.terms_tag
|
|
28
|
-
|
|
29
|
-
options[:content_html] ||= {}
|
|
30
|
-
merge_class! options[:content_html], storefront_config.content_class
|
|
31
|
-
|
|
32
|
-
options
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def definition(*args, &block)
|
|
36
|
-
options = args.extract_options!
|
|
37
|
-
key = args.shift
|
|
38
|
-
value = args.shift || block
|
|
39
|
-
locale_options = options.delete(:locale_options) || {}
|
|
40
|
-
label = t?(key, locale_options.reverse_merge(:scope => :"terms.labels"))
|
|
41
|
-
|
|
42
|
-
key_html = options.delete(:key_html) || {}
|
|
43
|
-
value_html = options.delete(:value_html) || {}
|
|
44
|
-
|
|
45
|
-
key_html.reverse_merge! clone_attributes(options)
|
|
46
|
-
value_html.reverse_merge! clone_attributes(options)
|
|
47
|
-
|
|
48
|
-
merge_class! key_html, storefront_config.term_key_class
|
|
49
|
-
merge_class! value_html, storefront_config.term_value_class
|
|
50
|
-
|
|
51
|
-
id_base = label.underscore.strip.gsub(/[\s|_]+/, storefront_config.separator).squeeze(storefront_config.separator)
|
|
52
|
-
|
|
53
|
-
key_html[:id] ||= "#{id_base}-key"
|
|
54
|
-
value_html[:id] ||= "#{id_base}-value"
|
|
55
|
-
|
|
56
|
-
separator = options[:separator] || @separator
|
|
57
|
-
|
|
58
|
-
label.gsub!(/#{separator}?$/, separator) if separator.present?
|
|
59
|
-
|
|
60
|
-
if storefront_config.include_aria
|
|
61
|
-
value_html[:role] ||= :definition
|
|
62
|
-
value_html[:"aria-labelledby"] = key_html[:id]
|
|
63
|
-
#value_html[:"aria-describedby"] = hint_html[:id]
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
if storefront_config.terms_tag == :table
|
|
67
|
-
_table_term(label, value, key_html, value_html)
|
|
68
|
-
else
|
|
69
|
-
_definiton_list_term(label, value, key_html, value_html)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
alias term definition
|
|
73
|
-
|
|
74
|
-
def definition_list(options = {}, &block)
|
|
75
|
-
@separator = options.has_key?(:separator) ? options[:separator] : storefront_config.term_separator
|
|
76
|
-
capture_haml do
|
|
77
|
-
haml_tag storefront_config.terms_tag do
|
|
78
|
-
yield
|
|
79
|
-
end
|
|
80
|
-
@separator = nil
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
alias terms definition_list
|
|
84
|
-
|
|
85
|
-
protected
|
|
86
|
-
def _definiton_list_term(label, value, key_html, value_html)
|
|
87
|
-
capture_haml do
|
|
88
|
-
haml_tag :dt, label, key_html
|
|
89
|
-
if value.is_a?(::Proc)
|
|
90
|
-
haml_tag :dd, value_html, &value
|
|
91
|
-
else
|
|
92
|
-
haml_tag :dd, value, value_html
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def _table_term(label, value, key_html, value_html)
|
|
98
|
-
capture_haml do
|
|
99
|
-
haml_tag :tr, :class => storefront_config.term_class do
|
|
100
|
-
haml_tag :td, label, key_html
|
|
101
|
-
if value.is_a?(::Proc)
|
|
102
|
-
haml_tag :td, value_html, &value
|
|
103
|
-
else
|
|
104
|
-
haml_tag :td, value, value_html
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
module Storefront
|
|
2
|
-
module ErrorHelper
|
|
3
|
-
def render_not_found(exception)
|
|
4
|
-
Exceptional::Catcher.handle_with_controller(exception, self, request) if defined?(::Exceptional)
|
|
5
|
-
logger.error(exception)
|
|
6
|
-
puts exception.inspect
|
|
7
|
-
puts exception.backtrace.join("\n")
|
|
8
|
-
render :template => "/error/404.html", :status => 404, :layout => false
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
module Storefront
|
|
2
|
-
module FlashHelper
|
|
3
|
-
def render_flash
|
|
4
|
-
flash_to_render = [:success, :failure, :notice, :error]
|
|
5
|
-
flash.select { |type, _| flash_to_render.include?(type) }.map do |type, content|
|
|
6
|
-
content_tag(:output, content, :class => "flash-#{type}")
|
|
7
|
-
end.join
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def flash?
|
|
11
|
-
flash.present?
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module Storefront
|
|
2
|
-
module FormHelper
|
|
3
|
-
def form_for(*args, &block)
|
|
4
|
-
Storefront::Form.new(self, *args).render(&block)
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def submit_for(text, url, options = {})
|
|
8
|
-
form_for(object, options.merge(:url => url)) do |form|
|
|
9
|
-
haml_concat Storefront::Form::Input.find(:submit).new(:value => text).render
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
module Storefront
|
|
2
|
-
module FormatHelper
|
|
3
|
-
def rendered_text(string)
|
|
4
|
-
string.to_s.
|
|
5
|
-
gsub(/<\/?[^>]*>/, '').
|
|
6
|
-
gsub(/\n/, " ").
|
|
7
|
-
gsub("\r", " ").
|
|
8
|
-
squeeze(" ").
|
|
9
|
-
gsub(/\"/, "″"). # convert quotes to inches
|
|
10
|
-
gsub(/\'/, "′"). # single quote to feet
|
|
11
|
-
gsub(/\$0?0*\.(\d+)/, "\\1¢").html_safe
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def format_money(value)
|
|
15
|
-
value.present? ? ("$" + number_with_precision(value.to_s.gsub("$", ""), :precision => 2)) : nil
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def format_percent(value)
|
|
19
|
-
value.present? ? (number_with_precision(value.to_s.gsub("%", ""), :precision => 0) + "%") : nil
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def sanitize(text)
|
|
23
|
-
text.gsub(/<\/?[^>]*>/, '').gsub(/\n/, " ").gsub("\r", " ").squeeze(" ")
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def n(value)
|
|
27
|
-
if value.respond_to?(:nan?) && value.nan?
|
|
28
|
-
0
|
|
29
|
-
else
|
|
30
|
-
value
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def s(string, default = "N/A")
|
|
35
|
-
string.present? ? string : default
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def num(num, default = "N/A")
|
|
39
|
-
result = number_with_precision(num, :precision => 1)
|
|
40
|
-
result.blank? ? default : result
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def money(value)
|
|
44
|
-
value ? value.to_s.gsub(/^\$?/, "$") : "$0"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def read_binary_file(path)
|
|
48
|
-
File.open(path, 'rb') {|f| f.read }
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def encoded_contents(path)
|
|
52
|
-
Base64.encode64(read_binary_file(path)).gsub(/\n/, '')
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def font_face_data_uri(path)
|
|
56
|
-
"url(\"data:font/truetype;base64,#{encoded_contents(path)}\")"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module Storefront
|
|
2
|
-
module ImageHelper
|
|
3
|
-
def image_tag(source, options = {})
|
|
4
|
-
options.symbolize_keys!
|
|
5
|
-
|
|
6
|
-
src = options[:src] = path_to_image(source)
|
|
7
|
-
|
|
8
|
-
unless src =~ /^cid:/
|
|
9
|
-
options[:alt] = options.fetch(:alt) { File.basename(src, '.*').gsub(/-\d+$/, "").gsub("-", " ").humanize }
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
if size = options.delete(:size)
|
|
13
|
-
options[:width], options[:height] = size.split("x") if size =~ %{^\d+x\d+$}
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
if mouseover = options.delete(:mouseover)
|
|
17
|
-
options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'"
|
|
18
|
-
options[:onmouseout] = "this.src='#{src}'"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
tag("img", options)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# http://snippets.dzone.com/posts/show/805
|
|
25
|
-
def read_image_size(path)
|
|
26
|
-
width, height = IO.read("#{Rails.root}/public/images/#{path}")[0x10..0x18].unpack('NN')
|
|
27
|
-
{:width => width, :height => height}
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|