Module: InTheZone

Extended by:
InTheZone
Included in:
InTheZone
Defined in:
lib/in_the_zone.rb,
lib/in_the_zone/version.rb

Constant Summary collapse

DefaultOptions =
{ format: "LLL" }.freeze
TagTemplate =
"<span class=\"<%= classes %>\" data-bind=\"localizeTime: { timestamp: <%= timestamp %>, format: '<%= time_format %>'<%= options %> }\"><%= time_string %></span>".freeze
VERSION =
"0.0.3"

Instance Method Summary collapse

Instance Method Details

#date_tag(date, opts = {}) ⇒ Object



22
23
24
25
26
# File 'lib/in_the_zone.rb', line 22

def date_tag( date, opts={} )
  opts[ :format ] ||= 'LL'
  opts[ :date_only ] = true
  time_tag( date.to_time, opts )
end

#javascript_pathObject



28
29
30
# File 'lib/in_the_zone.rb', line 28

def javascript_path
  @javascript_path ||= File.join( gem_asset_path, "javascripts", "inthezone.js" )
end

#set_tag_template(new_template) ⇒ Object Also known as: tag_template=



36
37
38
# File 'lib/in_the_zone.rb', line 36

def set_tag_template( new_template )
  @tag_template = Erubis::Eruby.new( new_template )
end

#stylesheet_pathObject



32
33
34
# File 'lib/in_the_zone.rb', line 32

def stylesheet_path
  @stylesheet_path ||= File.join( gem_asset_path, "stylesheets", "inthezone.css" )
end

#time_tag(time = Time.now.utc, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/in_the_zone.rb', line 13

def time_tag( time=Time.now.utc, opts={} )
  tag_data = normalize_opts( opts )
  options = tag_data[ :options ].inject([""]) do |acc, (k,v)|
    acc << "#{k}: #{ v.is_a?(String) ? "'#{v}'" : v.to_s }"
    acc
  end.join(", ")
  tag_template.result( tag_data.merge( time_string: time_string( time.utc, tag_data[ :format ] ), time_format: tag_data[ :format ], timestamp: time.utc.to_i, options: options ) )
end