Class: OrigenDocHelpers::FlowPageGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/origen_doc_helpers/flow_page_generator.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ FlowPageGenerator

Returns a new instance of FlowPageGenerator.



51
52
53
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 51

def initialize(options)
  @options = options
end

Class Attribute Details

.layoutObject

Returns the value of attribute layout.



5
6
7
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 5

def layout
  @layout
end

.layout_optionsObject

Returns the value of attribute layout_options.



4
5
6
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 4

def layout_options
  @layout_options
end

.pagesObject (readonly)

Returns the value of attribute pages.



6
7
8
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 6

def pages
  @pages
end

Class Method Details

.index_page_templateObject

index page template is in doc helpers, which isn’t using app/ dir



46
47
48
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 46

def index_page_template # index page template is in doc helpers, which isn't using app/ dir
  @index_page_template ||= "#{Origen.root!}/templates/flow_index.md.erb"
end

.page(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 23

def page(options)
  if !options[:name] || !(options[:flow] || options[:flows]) ||
     !options[:target]
    fail 'The following options are required: :name, :flow(s), :target'
  end
  p = new(options)
  pages[options[:group]] ||= []
  pages[options[:group]] << p
  p.run
end

.run(options) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 8

def run(options)
  @pages = {}
  unless options[:layout]
    fail 'You must pass a :layout option providing an absolute path to the layout file to be used'
  end
  unless File.exist?(options[:layout].to_s)
    fail "This layout file does not exist: #{options[:layout]}"
  end
  self.layout = options.delete(:layout)
  self.layout_options = options
  yield self
  write_index unless @pages.size == 0
  @pages = nil
end

.write_indexObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 34

def write_index
  f = "#{Origen.root}/web/content/flows.md"
  Origen.log.info "Building flow index page: #{f}"
  t = Origen.compile index_page_template,
                     layout:         layout,
                     layout_options: layout_options,
                     no_group_pages: pages.delete(nil),
                     pages:          pages

  File.write(f, t)
end

Instance Method Details

#flow_page_templateObject

flow page template is in doc helpers, which isn’t using app/ dir



102
103
104
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 102

def flow_page_template # flow page template is in doc helpers, which isn't using app/ dir
  @flow_page_template ||= "#{Origen.root!}/templates/flow_page.md.erb"
end

#flow_templateObject

flow template is in doc helpers, which isn’t using app/ dir



106
107
108
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 106

def flow_template # flow template is in doc helpers, which isn't using app/ dir
  @flow_template ||= "#{Origen.root!}/templates/shared/test/_flow.md.erb"
end

#headingObject



72
73
74
75
76
77
78
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 72

def heading
  if @options[:group]
    @options[:group] + ': ' + @options[:name]
  else
    @options[:name]
  end
end

#nameObject



68
69
70
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 68

def name
  @options[:name]
end

#output_dirObject



93
94
95
96
97
98
99
100
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 93

def output_dir
  d = "#{Origen.root}/web/content/flows"
  if @options[:group]
    d += ('/' + @options[:group].to_s.symbolize.to_s)
  end
  FileUtils.mkdir_p(d) unless File.exist?(d)
  d
end

#output_fileObject



80
81
82
83
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 80

def output_file
  f = @options[:name].to_s.symbolize
  "#{output_dir}/#{f}.md"
end

#output_pathObject



85
86
87
88
89
90
91
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 85

def output_path
  p = 'flows'
  if @options[:group]
    p += ('/' + @options[:group].to_s.symbolize.to_s)
  end
  p + '/' + @options[:name].to_s.symbolize.to_s
end

#runObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 55

def run
  Origen.log.info "Building flow page: #{output_file}"
  t = Origen.compile flow_page_template,
                     layout:         self.class.layout,
                     layout_options: self.class.layout_options,
                     flow_template:  flow_template,
                     heading:        heading,
                     target:         @options[:target],
                     flows:          [@options[:flows] || @options[:flow]].flatten,
                     context:        @options[:context] || {}
  File.write(output_file, t)
end