Class: TimelineSetter::CLI
- Inherits:
-
Object
- Object
- TimelineSetter::CLI
- Defined in:
- lib/timeline_setter/cli.rb
Instance Method Summary collapse
- #compile! ⇒ Object
- #events ⇒ Object
- #html ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #outdir ⇒ Object
- #parse_options! ⇒ Object
- #sheet ⇒ Object
- #timeline_page_path ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
6 7 8 |
# File 'lib/timeline_setter/cli.rb', line 6 def initialize end |
Instance Method Details
#compile! ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/timeline_setter/cli.rb', line 77 def compile! FileUtils.mkdir_p outdir unless File.exists? outdir if !@options[:no_assets] || !@options[:min] FileUtils.cp_r(Dir.glob("#{TimelineSetter::ROOT}/public/*"), outdir) # Concatenate JSTs to timeline-setter.js and remove templates.js `cat #{outdir}/javascripts/templates.js >> #{outdir}/javascripts/timeline-setter.js && rm -rf #{outdir}/javascripts/templates*` end File.open(timeline_page_path, 'w+') do |doc| doc.write html end puts "== Files copied to #{outdir}" if @options[:open] puts "== Opening ..." %x[ open #{timeline_page_path} ] end end |
#events ⇒ Object
58 59 60 |
# File 'lib/timeline_setter/cli.rb', line 58 def events TimelineSetter::Parser.new sheet end |
#html ⇒ Object
62 63 64 65 66 67 |
# File 'lib/timeline_setter/cli.rb', line 62 def html TimelineSetter::Timeline.new({ :events => events.events, :interval => @options[:interval] || '' }).send(@options[:min] ? :timeline_min : :timeline) end |
#outdir ⇒ Object
69 70 71 |
# File 'lib/timeline_setter/cli.rb', line 69 def outdir @options[:output] ? @options[:output] : "#{`pwd`.strip}/" end |
#parse_options! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/timeline_setter/cli.rb', line 10 def @options = {} option_parser = OptionParser.new do |opts| opts. = <<-BANNER TimelineSetter: A tool to generate HTML timelines from CSVs. Usage: BANNER opts.on('-c', '--csv CSV', 'CSV input file') do |c| @options[:csv] = c end opts.on('-o', '--output OUTPUT', 'Output directory to install timeline into.') do |o| @options[:output] = o end opts.on('-a', '--without-assets', 'Output timeline without supporting assets') do |a| @options[:no_assets] = a end opts.on('-O', '--open', 'Open generated timeline in a browser') do |o| @options[:open] = o end opts.on('-m', '--min', 'Create a minified one-page version of the timeline') do |m| @options[:min] = m end opts.on('-i', '--interval INTERVAL', 'Override automatic interval notches with a custom interval.') do |i| @options[:interval] = i end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end option_parser.parse! if @options.empty? puts option_parser.on_tail exit else compile! end end |
#sheet ⇒ Object
54 55 56 |
# File 'lib/timeline_setter/cli.rb', line 54 def sheet File.open(@options[:csv]).read end |
#timeline_page_path ⇒ Object
73 74 75 |
# File 'lib/timeline_setter/cli.rb', line 73 def timeline_page_path File.join(outdir, 'timeline.html') end |