Class: TimelineSetter::Timeline
- Inherits:
-
Object
- Object
- TimelineSetter::Timeline
- Defined in:
- lib/timeline_setter/timeline.rb
Instance Attribute Summary collapse
-
#timeline ⇒ Object
readonly
Create timeline HTML by interpolating events hash into an ERB template.
Instance Method Summary collapse
-
#initialize(events) ⇒ Timeline
constructor
Instantiate a new timeline from an events array created in Parser#initialize.
- #timeline_markup ⇒ Object
-
#timeline_min ⇒ Object
Create a minified one-page version of a timeline by minifying CSS and JS and embedding all assets into our ERB template.
- #tmpl(tmpl_file) ⇒ Object
-
#to_json ⇒ Object
Convert human dates to timestamps, sort the hash by timestamp, and convert the events hash to JSON to stick into our HTML.
Constructor Details
#initialize(events) ⇒ Timeline
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
#timeline ⇒ Object (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 end |
Instance Method Details
#timeline_markup ⇒ Object
17 18 19 |
# File 'lib/timeline_setter/timeline.rb', line 17 def timeline_markup tmpl("timeline-markup.erb") end |
#timeline_min ⇒ Object
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 |
#tmpl(tmpl_file) ⇒ Object
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 |
#to_json ⇒ Object
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 |