Class: ActionDoc::Generator
- Inherits:
-
Object
- Object
- ActionDoc::Generator
- Defined in:
- lib/actiondoc/generator.rb
Overview
The documentation generator class
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
Instance Method Summary collapse
- #check_action_yml ⇒ Object
- #construct_inputs_table(action) ⇒ Object
-
#initialize(args, options) ⇒ Generator
constructor
Initialize an instance of this ‘Generator` class.
- #read_action_yml ⇒ Object
- #read_template(action) ⇒ Object
- #render_template(template, action) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args, options) ⇒ Generator
Initialize an instance of this ‘Generator` class
35 36 37 38 39 |
# File 'lib/actiondoc/generator.rb', line 35 def initialize(args, ) @args = args @options = @padding = .fetch(:padding, :nice) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
32 33 34 |
# File 'lib/actiondoc/generator.rb', line 32 def args @args end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
32 33 34 |
# File 'lib/actiondoc/generator.rb', line 32 def @options end |
#padding ⇒ Object (readonly)
Returns the value of attribute padding.
32 33 34 |
# File 'lib/actiondoc/generator.rb', line 32 def padding @padding end |
Instance Method Details
#check_action_yml ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/actiondoc/generator.rb', line 63 def check_action_yml @path_to_action_yml = @args.first || 'action.yml' return if File.readable?(@path_to_action_yml) warn "#{@path_to_action_yml} not found! Aborting..." exit 1 end |
#construct_inputs_table(action) ⇒ Object
85 86 87 88 89 |
# File 'lib/actiondoc/generator.rb', line 85 def construct_inputs_table(action) return unless action.inputs && !action.inputs.empty? TableLayouts::Nice.new(Input.members_as_headers, action.inputs).layout end |
#read_action_yml ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/actiondoc/generator.rb', line 71 def read_action_yml yaml = YAML.safe_load(File.read(@path_to_action_yml)).deep_symbolize_keys inputs = yaml.fetch(:inputs, {}).map do |k, v| Input.new(k, v[:description].chomp, v[:required] ? 'Required' : 'No', v[:default]) end Action.new(yaml[:name], yaml[:description].chomp, inputs) end |
#read_template(action) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/actiondoc/generator.rb', line 48 def read_template(action) = [:template] if unless File.readable?() warn "Template file #{} not found! Aborting..." exit 1 end ERB.new(File.read(), trim_mode: '-') elsif action.inputs && !action.inputs.empty? ERB.new(DEFAULT_TEMPLATE, trim_mode: '-') else ERB.new(TEMPLATE_WITHOUT_INPUTS, trim_mode: '-') end end |
#render_template(template, action) ⇒ Object
79 80 81 82 83 |
# File 'lib/actiondoc/generator.rb', line 79 def render_template(template, action) inputs_table = construct_inputs_table(action) model = TemplateModel.new(action, inputs_table) puts template.result(model.instance_eval { binding }) end |
#run ⇒ Object
41 42 43 44 45 46 |
# File 'lib/actiondoc/generator.rb', line 41 def run check_action_yml action = read_action_yml template = read_template(action) render_template(template, action) end |