Class: Khaleesi::CLI::Produce

Inherits:
Khaleesi::CLI show all
Defined in:
lib/khaleesi/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Khaleesi::CLI

class_from_arg, #create_file_p, normalize_syntax

Constructor Details

#initialize(opts = {}) ⇒ Produce

Returns a new instance of Produce.



119
120
121
# File 'lib/khaleesi/cli.rb', line 119

def initialize(opts={})
  @input_file = opts[:input_file]
end

Instance Attribute Details

#input_fileObject (readonly)

Returns the value of attribute input_file.



117
118
119
# File 'lib/khaleesi/cli.rb', line 117

def input_file
  @input_file
end

Class Method Details

.descObject



85
86
87
# File 'lib/khaleesi/cli.rb', line 85

def self.desc
  'produce html code for specify markdown file'
end

.doc {|'usage: khaleesi produce <filename>'| ... } ⇒ Object

Yields:

  • ('usage: khaleesi produce <filename>')


89
90
91
92
93
94
95
# File 'lib/khaleesi/cli.rb', line 89

def self.doc
  return enum_for(:doc) unless block_given?

  yield 'usage: khaleesi produce <filename>'
  yield ''
  yield '<filename>  specify a file to read'
end

.parse(argv) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/khaleesi/cli.rb', line 97

def self.parse(argv)
  opts = {:input_file => nil}

  until argv.empty?
    opts[:input_file] = argv.shift
  end

  puts 'unspecific markdown file' unless opts[:input_file]

  new(opts)
end

Instance Method Details

#inputObject



113
114
115
# File 'lib/khaleesi/cli.rb', line 113

def input
  @input ||= input_stream.read
end

#input_streamObject



109
110
111
# File 'lib/khaleesi/cli.rb', line 109

def input_stream
  @input_stream ||= FileReader.new(@input_file)
end

#runObject



123
124
125
126
# File 'lib/khaleesi/cli.rb', line 123

def run
  return unless @input_file
  print Generator.new.handle_markdown(input)
end