module InTheZone

Constants

DefaultOptions
TagTemplate
VERSION

Public Instance Methods

date_tag( date, opts={} ) click to toggle source
# 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_path() click to toggle source
# 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 ) click to toggle source
# File lib/in_the_zone.rb, line 36
def set_tag_template( new_template )
  @tag_template = Erubis::Eruby.new( new_template )
end
Also aliased as: tag_template=
stylesheet_path() click to toggle source
# File lib/in_the_zone.rb, line 32
def stylesheet_path
  @stylesheet_path ||= File.join( gem_asset_path, "stylesheets", "inthezone.css" )
end
tag_template=( new_template )
Alias for: set_tag_template
time_tag( time=Time.now.utc, opts={} ) click to toggle source
# 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

Private Instance Methods

gem_asset_path() click to toggle source
# File lib/in_the_zone.rb, line 71
def gem_asset_path
  @gem_asset_path ||= File.expand_path( File.join( Pathname(__FILE__).dirname, "/../static_assets/" ) )
end
normalize_opts( opts ) click to toggle source
# File lib/in_the_zone.rb, line 51
def normalize_opts( opts )
  data = DefaultOptions.dup
  data[ :classes ] = [ 'local-time' ]
  data[ :options ] = {}
  if opts[ :from_now ]
    data[ :options ][ :from_now ] = true
  end
  if opts[ :format_method ]
    data[ :options ][ :format_method ] = opts[ :format_method ].to_s
  end
  if opts[ :live_update ]
    data[ :options ][ :live_update ] = true
  end
  if opts[ :format ]
    data[ :format ] = opts[ :format ]
  end
  data[ :classes ] = data[ :classes ].sort.join(" ")
  data
end
tag_template() click to toggle source
# File lib/in_the_zone.rb, line 43
def tag_template
  @tag_template ||= Erubis::Eruby.new( TagTemplate.dup )
end
time_string( time, fmt ) click to toggle source
# File lib/in_the_zone.rb, line 47
def time_string( time, fmt )
  LDML.format( time, fmt )
end