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.



55
56
57
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 55

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



46
47
48
49
50
51
52
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 46

def index_page_template
  if File.exist?("#{Origen.root}/app/")
    @index_page_template ||= "#{Origen.root!}/app/templates/flow_index.md.erb"
  else
    @index_page_template ||= "#{Origen.root!}/templates/flow_index.md.erb"
  end
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



106
107
108
109
110
111
112
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 106

def flow_page_template
  if File.exist?("#{Origen.root}/app/")
    @flow_page_template ||= "#{Origen.root!}/app/templates/flow_page.md.erb"
  else
    @flow_page_template ||= "#{Origen.root!}/templates/flow_page.md.erb"
  end
end

#flow_templateObject



114
115
116
117
118
119
120
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 114

def flow_template
  if File.exist?("#{Origen.root}/app/")
    @flow_template ||= "#{Origen.root!}/app/templates/shared/test/_flow.md.erb"
  else
    @flow_template ||= "#{Origen.root!}/templates/shared/test/_flow.md.erb"
  end
end

#headingObject



76
77
78
79
80
81
82
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 76

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

#nameObject



72
73
74
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 72

def name
  @options[:name]
end

#output_dirObject



97
98
99
100
101
102
103
104
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 97

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



84
85
86
87
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 84

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

#output_pathObject



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

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



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/origen_doc_helpers/flow_page_generator.rb', line 59

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