timeline_setter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/.document +4 -0
  2. data/LICENSE.txt +18 -0
  3. data/README +15 -0
  4. data/Rakefile +98 -0
  5. data/bin/timeline-setter +9 -0
  6. data/doc/doc.markdown +253 -0
  7. data/doc/doc_wrapper.erb +87 -0
  8. data/doc/docco.css +186 -0
  9. data/doc/timeline-setter.html +592 -0
  10. data/doc/todo.markdown +28 -0
  11. data/doc/twitter-demo.html +122 -0
  12. data/documentation/TimelineSetter/CLI.html +575 -0
  13. data/documentation/TimelineSetter/Parser.html +285 -0
  14. data/documentation/TimelineSetter/Timeline.html +513 -0
  15. data/documentation/TimelineSetter/Util.html +246 -0
  16. data/documentation/TimelineSetter.html +112 -0
  17. data/documentation/_index.html +132 -0
  18. data/documentation/class_list.html +36 -0
  19. data/documentation/css/common.css +1 -0
  20. data/documentation/css/full_list.css +53 -0
  21. data/documentation/css/style.css +318 -0
  22. data/documentation/file.README.html +70 -0
  23. data/documentation/file_list.html +38 -0
  24. data/documentation/frames.html +13 -0
  25. data/documentation/index.html +70 -0
  26. data/documentation/js/app.js +203 -0
  27. data/documentation/js/full_list.js +149 -0
  28. data/documentation/js/jquery.js +16 -0
  29. data/documentation/method_list.html +155 -0
  30. data/documentation/top-level-namespace.html +88 -0
  31. data/index.html +397 -0
  32. data/lib/timeline_setter/cli.rb +85 -0
  33. data/lib/timeline_setter/parser.rb +28 -0
  34. data/lib/timeline_setter/timeline.rb +44 -0
  35. data/lib/timeline_setter/version.rb +3 -0
  36. data/lib/timeline_setter.rb +22 -0
  37. data/public/javascripts/timeline-setter.js +822 -0
  38. data/public/javascripts/vendor/jquery-min.js +16 -0
  39. data/public/javascripts/vendor/underscore-min.js +26 -0
  40. data/public/stylesheets/timeline-setter.css +396 -0
  41. data/spec/spec_helper.rb +10 -0
  42. data/spec/test_data.csv +4 -0
  43. data/spec/timeline_setter_spec.rb +85 -0
  44. data/templates/timeline-markup.erb +61 -0
  45. data/templates/timeline-min.erb +1 -0
  46. data/templates/timeline.erb +12 -0
  47. data/timeline_setter.gemspec +104 -0
  48. metadata +189 -0
@@ -0,0 +1,85 @@
1
+ require 'optparse'
2
+ require 'fileutils'
3
+
4
+ module TimelineSetter
5
+ class CLI
6
+ def initialize
7
+ parse_options!
8
+ end
9
+
10
+ def parse_options!
11
+ @options = {}
12
+ option_parser = OptionParser.new do |opts|
13
+ opts.banner = <<-BANNER
14
+ TimelineSetter: A tool to generate HTML timelines from CSVs.
15
+
16
+ Usage:
17
+ BANNER
18
+
19
+ opts.on('-c', '--csv CSV', 'CSV input file') do |c|
20
+ @options[:csv] = c
21
+ end
22
+ opts.on('-o', '--output OUTPUT', 'Output directory to install timeline into.') do |o|
23
+ @options[:output] = o
24
+ end
25
+ opts.on('-a', '--with-assets', 'Output timeline supporting assets as well') do |a|
26
+ @options[:assets] = a
27
+ end
28
+ opts.on('-O', '--open', 'Open generated timeline in a browser') do |o|
29
+ @options[:open] = o
30
+ end
31
+ opts.on('-m', '--min', 'Create a minified one-page version of the timeline') do |m|
32
+ @options[:min] = m
33
+ end
34
+
35
+
36
+ opts.on_tail("-h", "--help", "Show this message") do
37
+ puts opts
38
+ exit
39
+ end
40
+ end
41
+ option_parser.parse!
42
+
43
+ if @options.empty?
44
+ puts option_parser.on_tail
45
+ exit
46
+ else
47
+ compile!
48
+ end
49
+ end
50
+
51
+ def sheet
52
+ File.open(@options[:csv]).read
53
+ end
54
+
55
+ def events
56
+ TimelineSetter::Parser.new sheet
57
+ end
58
+
59
+ def html
60
+ TimelineSetter::Timeline.new(events.events).send(@options[:min] ? :timeline_min : :timeline)
61
+ end
62
+
63
+ def outdir
64
+ @options[:output] ? @options[:output] : "#{`pwd`.strip}/"
65
+ end
66
+
67
+ def compile!
68
+ if @options[:assets]
69
+ FileUtils.cp_r(Dir.glob("#{TimelineSetter::ROOT}/public/*"), outdir)
70
+ end
71
+
72
+ File.open(outdir + 'timeline.html', 'w+') do |doc|
73
+ doc.write html
74
+ end
75
+
76
+ puts "== Files copied to #{outdir}"
77
+
78
+ if @options[:open]
79
+ puts "== Opening ..."
80
+ %x{ open #{outdir}timeline.html }
81
+ end
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,28 @@
1
+ module TimelineSetter
2
+ class Parser
3
+ attr_reader :events
4
+
5
+ # Initialize a new timeline from a CSV file via TableFu,
6
+ # add a hash for each row (event) in the sheet to an events array.
7
+ # Sheet should contain columns for
8
+ # * date
9
+ # * display_date
10
+ # * description
11
+ # * link
12
+ # * thumbnail
13
+ # * series
14
+ # * html
15
+ #
16
+ def initialize(sheet)
17
+ @events = []
18
+ spreadsheet = TableFu.new(sheet) do |s|
19
+ s.columns = %w[date display_date description link series html]
20
+ end
21
+
22
+ spreadsheet.rows.each do |row|
23
+ hash = spreadsheet.columns.inject({}) {|memo, column| memo[column.to_sym] = row[column].to_s ; memo}
24
+ @events << hash
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,44 @@
1
+ module TimelineSetter
2
+ class Timeline
3
+ attr_reader :timeline
4
+ # Instantiate a new timeline from an events
5
+ # array created in Parser#initialize
6
+ def initialize(events)
7
+ @events = events
8
+ end
9
+
10
+ # Convert human dates to timestamps, sort the hash by timestamp, and
11
+ # convert the events hash to JSON to stick into our HTML.
12
+ def to_json
13
+ @events.collect {|r| r[:timestamp] = Time.parse(r[:date]).to_i * 1000 }.sort{|a,b| b[:timestamp] <=> a[:timestamp]}
14
+ @events.to_json
15
+ end
16
+
17
+ def timeline_markup
18
+ tmpl("timeline-markup.erb")
19
+ end
20
+
21
+ # Create timeline HTML by interpolating events hash into an ERB template.
22
+ # Re-template timeline by editing ../templates/timeline.erb
23
+ # This version preserves external links to CSS and JS.
24
+ def timeline
25
+ @timeline = tmpl("timeline.erb")
26
+ end
27
+
28
+ # Create a minified one-page version of a timeline by minifying CSS and JS and embedding all assets
29
+ # into our ERB template.
30
+ def timeline_min
31
+ @js = ""
32
+ @css = Kompress::CSS.new(File.open("#{TimelineSetter::ROOT}/public/stylesheets/timeline-setter.css").read).css
33
+ libs = Dir.glob("#{TimelineSetter::ROOT}/public/javascripts/vendor/**")
34
+ libs.each { |lib| @js << File.open(lib,'r').read }
35
+ @min_html = Kompress::HTML.new(timeline_markup).html
36
+ @js << Closure::Compiler.new.compile(File.open("#{TimelineSetter::ROOT}/public/javascripts/timeline-setter.js", 'r'))
37
+ @timeline = tmpl("timeline-min.erb")
38
+ end
39
+
40
+ def tmpl(tmpl_file)
41
+ ERB.new(File.open("#{TimelineSetter::ROOT}/templates/#{tmpl_file}").read).result(binding)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module TimelineSetter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,22 @@
1
+
2
+ module TimelineSetter
3
+ ROOT = File.expand_path "#{File.dirname __FILE__}/.."
4
+ end
5
+
6
+ require 'date'
7
+ require 'time'
8
+ require 'erb'
9
+ require 'table_fu'
10
+ require 'json'
11
+ require 'kompress'
12
+
13
+ begin
14
+ require 'closure-compiler'
15
+ rescue LoadError
16
+ puts "== Warning, the closure-compiler gem is required to generate minified timelines"
17
+ end
18
+
19
+
20
+ require "#{TimelineSetter::ROOT}/lib/timeline_setter/version"
21
+ require "#{TimelineSetter::ROOT}/lib/timeline_setter/parser"
22
+ require "#{TimelineSetter::ROOT}/lib/timeline_setter/timeline"