Module: GreenMonkey::ViewHelper
- Defined in:
- lib/green_monkey/ext/view_helper.rb
Instance Method Summary collapse
- #breadcrumb_link_to(title, path, options = {}) ⇒ Object
- #mida_scope(object) ⇒ Object
-
#time_tag(time, *args) ⇒ Object
time_tag post.created_at = time_tag post.created_at, format: “%d %h %Y %R%p” = time_tag post.created_at, itemprop: “datePublished”.
-
#time_tag_interval(from, to, *args) ⇒ Object
as second argumnts can get as Time/DateTime object as duration in seconds.
- #time_to_iso8601(time) ⇒ Object
Instance Method Details
#breadcrumb_link_to(title, path, options = {}) ⇒ Object
80 81 82 83 84 |
# File 'lib/green_monkey/ext/view_helper.rb', line 80 def (title, path, = {}) content_tag(:span, itemscope: true, itemtype: 'http://data-vocabulary.org/Breadcrumb') do link_to(content_tag(:span, title, itemprop: 'title'), path, .merge(itemprop: 'url')) + '' end end |
#mida_scope(object) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/green_monkey/ext/view_helper.rb', line 62 def mida_scope(object) = {itemscope: true} if object.respond_to?(:html_schema_type) if object.html_schema_type.kind_of?(Mida::Vocabulary) .merge! itemtype: object.html_schema_type.itemtype.source else raise "No vocabulary found (#{obj.html_schema_type})" unless Mida::Vocabulary.find(obj.html_schema_type) .merge! itemtype: object.html_schema_type end elsif object.is_a?(Symbol) .merge! itemtype: Mida(object) elsif object.is_a?(String) .merge! itemtype: object end () end |
#time_tag(time, *args) ⇒ Object
time_tag post.created_at
time_tag post.created_at, format: “%d %h %Y %R%p”
time_tag post.created_at, itemprop: “datePublished”
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/green_monkey/ext/view_helper.rb', line 13 def time_tag(time, *args) = args. format = .delete(:format) || :long datetime = time_to_iso8601(time) if time.acts_like?(:time) title = nil content = args.first || I18n.l(time, format: format) elsif time.kind_of?(Numeric) title = ChronicDuration.output(time, :format => format) content = args.first || distance_of_time_in_words(time) else content = time.to_s end content_tag(:time, content, .reverse_merge(datetime: datetime, title: title)) end |
#time_tag_interval(from, to, *args) ⇒ Object
as second argumnts can get as Time/DateTime object as duration in seconds
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/green_monkey/ext/view_helper.rb', line 32 def time_tag_interval(from, to, *args) = args. format = .delete(:format) || :long datetime = [from, to].map(&method(:time_to_iso8601)).join("/") content = args.first || [from, to].map do |time| if time.acts_like?(:time) I18n.l(from, format: format) else ChronicDuration.output(time, :format => format) end end if to.acts_like?(:time) content = content.join(" - ") else content = content.join(" in ") end content_tag(:time, content, .reverse_merge(datetime: datetime)) end |
#time_to_iso8601(time) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/green_monkey/ext/view_helper.rb', line 54 def time_to_iso8601(time) if time.acts_like?(:time) time.iso8601 elsif time.kind_of?(Numeric) ChronicDuration.output(time, :format => :iso8601) end end |