Class: TimelineSetter::Timeline
- Inherits:
-
Object
- Object
- TimelineSetter::Timeline
- Defined in:
- lib/timeline_setter/timeline.rb
Instance Attribute Summary (collapse)
-
- (Object) timeline
readonly
Create timeline HTML by interpolating events hash into an ERB template.
Instance Method Summary (collapse)
-
- (Timeline) initialize(events)
constructor
Instantiate a new timeline from an events array created in Parser#initialize.
- - (Object) timeline_markup
-
- (Object) timeline_min
Create a minified one-page version of a timeline by minifying CSS and JS and embedding all assets into our ERB template.
- - (Object) tmpl(tmpl_file)
-
- (Object) to_json
Convert human dates to timestamps, sort the hash by timestamp, and convert the events hash to JSON to stick into our HTML.
Constructor Details
- (Timeline) initialize(events)
Instantiate a new timeline from an events array created in Parser#initialize
6 7 8 |
# File 'lib/timeline_setter/timeline.rb', line 6 def initialize(events) @events = events end |
Instance Attribute Details
- (Object) timeline (readonly)
Create timeline HTML by interpolating events hash into an ERB template. Re-template timeline by editing ../templates/timeline.erb This version preserves external links to CSS and JS.
24 25 26 |
# File 'lib/timeline_setter/timeline.rb', line 24 def timeline @timeline = tmpl("timeline.erb") end |
Instance Method Details
- (Object) timeline_markup
17 18 19 |
# File 'lib/timeline_setter/timeline.rb', line 17 def timeline_markup tmpl("timeline-markup.erb") end |
- (Object) timeline_min
Create a minified one-page version of a timeline by minifying CSS and JS and embedding all assets into our ERB template.
30 31 32 33 34 35 36 37 38 |
# File 'lib/timeline_setter/timeline.rb', line 30 def timeline_min @js = "" @css = Kompress::CSS.new(File.open("#{TimelineSetter::ROOT}/public/stylesheets/timeline-setter.css").read).css libs = Dir.glob("#{TimelineSetter::ROOT}/public/javascripts/vendor/**") libs.each { |lib| @js << File.open(lib,'r').read } @min_html = Kompress::HTML.new(timeline_markup).html @js << Closure::Compiler.new.compile(File.open("#{TimelineSetter::ROOT}/public/javascripts/timeline-setter.js", 'r')) @timeline = tmpl("timeline-min.erb") end |
- (Object) tmpl(tmpl_file)
40 41 42 |
# File 'lib/timeline_setter/timeline.rb', line 40 def tmpl(tmpl_file) ERB.new(File.open("#{TimelineSetter::ROOT}/templates/#{tmpl_file}").read).result(binding) end |
- (Object) to_json
Convert human dates to timestamps, sort the hash by timestamp, and convert the events hash to JSON to stick into our HTML.
12 13 14 15 |
# File 'lib/timeline_setter/timeline.rb', line 12 def to_json @events.each {|r| r[:timestamp] = Time.parse(r[:date]).to_i * 1000 } @events.to_json end |