origen_doc_helpers 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/fix_my_workspace +100 -0
- data/config/commands.rb +11 -11
- data/config/version.rb +2 -2
- data/lib/origen_doc_helpers.rb +1 -0
- data/lib/origen_doc_helpers/guide_index.rb +162 -0
- data/lib/origen_doc_helpers/helpers.rb +7 -0
- data/templates/shared/_searchable.html.erb +1 -0
- data/templates/web/helpers/searchable/intro.md.erb +45 -0
- data/templates/web/layouts/_doc.html.erb +10 -10
- metadata +5 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f10206613a76375cd6ec5925e33ea6a4928585a5
|
4
|
+
data.tar.gz: 713eef54df6cbaa62ce7b30b9bf63aba164b29c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e64c3ceefca6c63d72b561a20c5ca6bfd776e4ed62e1c0f2447757f31dd8f80d73b6505ae26703a49e3192f75451d2428297e8e7b7e69b2c53d369b5dbe7efe2
|
7
|
+
data.tar.gz: 13036d3ddafdbed4126f94f752e6e9f667a62d351b6e56523047fce98ce918f9779953343db3e9a5456fe59e324584708f22fac1d25fe108bac672fe91ae24b5
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$VERBOSE = nil # Don't care about world writable dir warnings and the like
|
3
|
+
|
4
|
+
if $_fix_my_workspace_version_check
|
5
|
+
$_fix_my_workspace_version = '0.7.0'
|
6
|
+
else
|
7
|
+
if File.exist?(File.expand_path('../../lib/origen.rb', __FILE__))
|
8
|
+
# If this script is being run from within an origen-core workspace, use that Origen-core,
|
9
|
+
# not the system-installed origen-core version.
|
10
|
+
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
|
11
|
+
require 'origen'
|
12
|
+
else
|
13
|
+
# Use system-installed Origen (the gem in system Ruby)
|
14
|
+
require 'origen'
|
15
|
+
end
|
16
|
+
|
17
|
+
if !Origen.site_config.gem_manage_bundler
|
18
|
+
puts 'Sorry but you have opted to manage Bundler yourself via your Origen site config, and this means'
|
19
|
+
puts 'that I cannot make certain assumptions about how your workspace is configured.'
|
20
|
+
puts 'You will need to either resolve this problem yourself, or else change the value of'
|
21
|
+
puts 'gem_mange_bundler to true.'
|
22
|
+
puts 'See here for more details on how to do that: http://origen-sdk.org/origen/guides/starting/company/'
|
23
|
+
|
24
|
+
else
|
25
|
+
ENV['BUNDLE_GEMFILE'] = File.join(Origen.root, 'Gemfile')
|
26
|
+
ENV['BUNDLE_PATH'] = File.expand_path(Origen.site_config.gem_install_dir)
|
27
|
+
ENV['BUNDLE_BIN'] = File.join(Origen.root, 'lbin')
|
28
|
+
|
29
|
+
# Force copy system gems to local gems
|
30
|
+
if Origen.site_config.gem_use_from_system
|
31
|
+
local_gem_dir = "#{ENV['BUNDLE_PATH']}/ruby/#{Pathname.new(Gem.dir).basename}"
|
32
|
+
gem_dir = Pathname.new(Gem.dir)
|
33
|
+
|
34
|
+
Origen.site_config.gem_use_from_system.each do |gem, version|
|
35
|
+
begin
|
36
|
+
# This will raise an error if the system doesn't have this gem installed, that
|
37
|
+
# will be rescued below
|
38
|
+
spec = Gem::Specification.find_by_name(gem, version)
|
39
|
+
|
40
|
+
local_dir = File.join(local_gem_dir, Pathname.new(spec.gem_dir).relative_path_from(gem_dir))
|
41
|
+
FileUtils.mkdir_p local_dir
|
42
|
+
FileUtils.cp_r("#{spec.gem_dir}/.", local_dir)
|
43
|
+
|
44
|
+
local_file = Pathname.new(File.join(local_gem_dir, Pathname.new(spec.cache_file).relative_path_from(gem_dir)))
|
45
|
+
FileUtils.mkdir_p local_file.dirname
|
46
|
+
FileUtils.cp(spec.cache_file, local_file)
|
47
|
+
|
48
|
+
if spec.extension_dir && File.exist?(spec.extension_dir)
|
49
|
+
local_dir = File.join(local_gem_dir, Pathname.new(spec.extension_dir).relative_path_from(gem_dir))
|
50
|
+
FileUtils.mkdir_p local_dir
|
51
|
+
FileUtils.cp_r("#{spec.extension_dir}/.", local_dir)
|
52
|
+
end
|
53
|
+
|
54
|
+
local_file = Pathname.new(File.join(local_gem_dir, Pathname.new(spec.spec_file).relative_path_from(gem_dir)))
|
55
|
+
FileUtils.mkdir_p local_file.dirname
|
56
|
+
FileUtils.cp(spec.spec_file, local_file)
|
57
|
+
|
58
|
+
rescue Gem::LoadError
|
59
|
+
# This just means that one of the gems that should be copied from the system
|
60
|
+
# was not actually installed in the system, so nothing we can do about that here
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Delete lbin
|
66
|
+
FileUtils.rm_rf(ENV['BUNDLE_BIN']) if File.exist?(ENV['BUNDLE_BIN'])
|
67
|
+
|
68
|
+
# Run bundler with correct switches
|
69
|
+
cmd = "bundle install --gemfile #{ENV['BUNDLE_GEMFILE']} --binstubs #{ENV['BUNDLE_BIN']} --path #{ENV['BUNDLE_PATH']}"
|
70
|
+
`chmod o-w #{Origen.root}` # Stops some annoying world writable warnings during install
|
71
|
+
`chmod o-w #{Origen.root}/bin` if File.exist?("#{Origen.root}/bin")
|
72
|
+
`chmod o-w #{Origen.root}/.bin` if File.exist?("#{Origen.root}/.bin")
|
73
|
+
|
74
|
+
# Try again, this time updating the bundle
|
75
|
+
if system(cmd)
|
76
|
+
fixed = true
|
77
|
+
elsif system 'bundle update'
|
78
|
+
fixed = true
|
79
|
+
end
|
80
|
+
|
81
|
+
if File.exist?(ENV['BUNDLE_BIN'])
|
82
|
+
`chmod o-w #{ENV['BUNDLE_BIN']}`
|
83
|
+
|
84
|
+
# Make .bat versions of all executables, Bundler should really be doing this when running
|
85
|
+
# on windows
|
86
|
+
if Origen.os.windows?
|
87
|
+
Dir.glob("#{ENV['BUNDLE_BIN']}/*").each do |bin|
|
88
|
+
unless bin =~ /.bat$/
|
89
|
+
bat = "#{bin}.bat"
|
90
|
+
unless File.exist?(bat)
|
91
|
+
File.open(bat, 'w') { |f| f.write('@"ruby.exe" "%~dpn0" %*') }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
system 'origen -v' if fixed
|
99
|
+
end
|
100
|
+
end
|
data/config/commands.rb
CHANGED
@@ -20,14 +20,14 @@ aliases ={
|
|
20
20
|
# Now branch to the specific task code
|
21
21
|
case @command
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
when "
|
26
|
-
|
27
|
-
require "
|
28
|
-
|
29
|
-
#
|
30
|
-
|
23
|
+
## Example of how to make a command to run unit tests, this simply invokes RSpec on
|
24
|
+
## the spec directory
|
25
|
+
when "specs"
|
26
|
+
ARGV.unshift "spec"
|
27
|
+
require "rspec"
|
28
|
+
require "rspec/autorun"
|
29
|
+
exit 0 # This will never be hit on a fail, RSpec will automatically exit 1
|
30
|
+
|
31
31
|
|
32
32
|
# Always leave an else clause to allow control to fall back through to the
|
33
33
|
# Origen command handler.
|
@@ -35,8 +35,8 @@ when "execute"
|
|
35
35
|
# origen -h, you can do this be assigning the required text to @application_commands
|
36
36
|
# before handing control back to Origen. Un-comment the example below to get started.
|
37
37
|
else
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
@application_commands = <<-EOT
|
39
|
+
specs Run the specs (tests), -c will enable coverage
|
40
|
+
EOT
|
41
41
|
|
42
42
|
end
|
data/config/version.rb
CHANGED
data/lib/origen_doc_helpers.rb
CHANGED
@@ -7,6 +7,7 @@ module OrigenDocHelpers
|
|
7
7
|
autoload :ListFlowFormatter, 'origen_doc_helpers/list_flow_formatter'
|
8
8
|
autoload :FlowPageGenerator, 'origen_doc_helpers/flow_page_generator'
|
9
9
|
autoload :ModelPageGenerator, 'origen_doc_helpers/model_page_generator'
|
10
|
+
autoload :GuideIndex, 'origen_doc_helpers/guide_index'
|
10
11
|
end
|
11
12
|
|
12
13
|
require 'origen_doc_helpers/helpers'
|
@@ -0,0 +1,162 @@
|
|
1
|
+
module OrigenDocHelpers
|
2
|
+
# Provides an API to programatically construct an index hash as used
|
3
|
+
# by the Searchable Documents helper -
|
4
|
+
# http://origen-sdk.org/doc_helpers/helpers/searchable/intro/#The_Document_Index
|
5
|
+
class GuideIndex
|
6
|
+
def initialize
|
7
|
+
@index = {}
|
8
|
+
@section_keys = {}
|
9
|
+
@pending_sections = []
|
10
|
+
@pending_pages = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def section(id, options = {}, &block)
|
14
|
+
@current_section_id = id
|
15
|
+
if options[:heading]
|
16
|
+
# This is to handle the corner case where an id reference was originally supplied
|
17
|
+
# without the heading, then a later reference added the heading
|
18
|
+
if @section_keys[id]
|
19
|
+
if @section_keys[id] != options[:heading]
|
20
|
+
change_key(:@index, @section_keys[id], options[:heading])
|
21
|
+
@section_keys[id] = options[:heading]
|
22
|
+
end
|
23
|
+
else
|
24
|
+
@section_keys[id] = options[:heading]
|
25
|
+
end
|
26
|
+
else
|
27
|
+
@section_keys[id] ||= id
|
28
|
+
end
|
29
|
+
@section_keys[id] ||= @section_keys[id].to_s if @section_keys[id]
|
30
|
+
section_pending = false
|
31
|
+
unless @index[section_key]
|
32
|
+
if options[:after]
|
33
|
+
if has_key?(:@index, section_key(options[:after]))
|
34
|
+
insert_after(:@index, section_key, section_key(options[:after]), {})
|
35
|
+
else
|
36
|
+
@pending_sections << [id, options.dup, block] unless @no_pending
|
37
|
+
section_pending = true
|
38
|
+
end
|
39
|
+
elsif options[:before]
|
40
|
+
if has_key?(:@index, section_key(options[:before]))
|
41
|
+
insert_before(:@index, section_key, section_key(options[:before]), {})
|
42
|
+
else
|
43
|
+
@pending_sections << [id, options.dup, block] unless @no_pending
|
44
|
+
section_pending = true
|
45
|
+
end
|
46
|
+
else
|
47
|
+
@index[section_key] = {}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
@current_section = @index[section_key]
|
51
|
+
yield self unless section_pending
|
52
|
+
@current_section = nil
|
53
|
+
|
54
|
+
# See if any pending sections can now be inserted
|
55
|
+
unless @no_pending
|
56
|
+
@pending_sections.each do |id, opts, blk|
|
57
|
+
@no_pending = true
|
58
|
+
section(id, opts, &blk)
|
59
|
+
@no_pending = false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
def page(id, options = {})
|
66
|
+
unless @current_section
|
67
|
+
fail 'page can only be called from within a section block!'
|
68
|
+
end
|
69
|
+
@current_topic_id = id
|
70
|
+
value = options[:heading] || id
|
71
|
+
value = value.to_s if value
|
72
|
+
page_pending = false
|
73
|
+
if options[:after]
|
74
|
+
if has_key?(:@current_section, topic_key(options[:after]))
|
75
|
+
insert_after(:@current_section, topic_key, topic_key(options[:after]), value)
|
76
|
+
else
|
77
|
+
@pending_pages << [id, options.dup] unless @no_page_pending
|
78
|
+
page_pending = true
|
79
|
+
end
|
80
|
+
elsif options[:before]
|
81
|
+
if has_key?(:@current_section, topic_key(options[:before]))
|
82
|
+
insert_before(:@current_section, topic_key, topic_key(options[:before]), value)
|
83
|
+
else
|
84
|
+
@pending_pages << [id, options.dup] unless @no_page_pending
|
85
|
+
page_pending = true
|
86
|
+
end
|
87
|
+
else
|
88
|
+
@current_section[topic_key] = value
|
89
|
+
end
|
90
|
+
# Update the parent reference, required if before or after was used to create a new
|
91
|
+
# @current_section hash
|
92
|
+
@index[section_key] = @current_section unless page_pending
|
93
|
+
|
94
|
+
# See if any pending pages can now be inserted
|
95
|
+
unless @no_page_pending
|
96
|
+
@pending_pages.each do |id, opts|
|
97
|
+
@no_page_pending = true
|
98
|
+
page(id, opts)
|
99
|
+
@no_page_pending = false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_h
|
107
|
+
@index
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def section_key(id = nil)
|
113
|
+
@section_keys[id || @current_section_id]
|
114
|
+
end
|
115
|
+
|
116
|
+
def topic_key(id = nil)
|
117
|
+
if @current_section_id
|
118
|
+
"#{@current_section_id}_#{id || @current_topic_id}".to_sym
|
119
|
+
else
|
120
|
+
"#{id || @current_topic_id}".to_sym
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def has_key?(var, id)
|
125
|
+
instance_variable_get(var).key?(id)
|
126
|
+
end
|
127
|
+
|
128
|
+
def change_key(var, existing, new)
|
129
|
+
h = {}
|
130
|
+
instance_variable_get(var).each do |key, val|
|
131
|
+
if key == existing
|
132
|
+
h[new] = val
|
133
|
+
else
|
134
|
+
h[key] = val
|
135
|
+
end
|
136
|
+
end
|
137
|
+
instance_variable_set(var, h)
|
138
|
+
end
|
139
|
+
|
140
|
+
def insert_after(var, id, after, value)
|
141
|
+
new = {}
|
142
|
+
instance_variable_get(var).each do |key, val|
|
143
|
+
new[key] = val
|
144
|
+
if key == after
|
145
|
+
new[id] = value
|
146
|
+
end
|
147
|
+
end
|
148
|
+
instance_variable_set(var, new)
|
149
|
+
end
|
150
|
+
|
151
|
+
def insert_before(var, id, before, value)
|
152
|
+
new = {}
|
153
|
+
instance_variable_get(var).each do |key, val|
|
154
|
+
if key == before
|
155
|
+
new[id] = value
|
156
|
+
end
|
157
|
+
new[key] = val
|
158
|
+
end
|
159
|
+
instance_variable_set(var, new)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -273,6 +273,13 @@ END
|
|
273
273
|
options[:tab]
|
274
274
|
else
|
275
275
|
rel = options[:top_level_file].relative_path_from(_doc_root_dir(options)).sub_ext('').sub_ext('').to_s
|
276
|
+
# If the file lives outside of the current app (e.g. it comes from a plugin), then the above approach
|
277
|
+
# doesn't work, so let's just take the last dirname and the filename
|
278
|
+
if rel =~ /\.\./
|
279
|
+
dir = options[:top_level_file].dirname.basename
|
280
|
+
file = options[:top_level_file].basename('.*').basename('.*') # twice to allow for my_file.md.erb
|
281
|
+
rel = "#{dir}_#{file}"
|
282
|
+
end
|
276
283
|
rel.gsub(/(\/|\\)/, '_').downcase.to_sym
|
277
284
|
end
|
278
285
|
end
|
@@ -43,6 +43,51 @@ index["Topic 1"] = {
|
|
43
43
|
}
|
44
44
|
~~~
|
45
45
|
|
46
|
+
#### Guide Index API
|
47
|
+
|
48
|
+
An API is available to programatically define the document index, here is the first example above defined
|
49
|
+
via the API rather than creating the hash explicitly:
|
50
|
+
|
51
|
+
~~~ruby
|
52
|
+
index = OrigenDocHelpers::GuideIndex.new
|
53
|
+
index.section nil do |section|
|
54
|
+
section.page :intro, heading: "Introduction"
|
55
|
+
section.page :page2, heading: "Page 2"
|
56
|
+
end
|
57
|
+
index.section :topic1, heading: "Topic 1" do |section|
|
58
|
+
section.page :item1, heading: "First Item"
|
59
|
+
section.page :item2, heading: "Second Item"
|
60
|
+
end
|
61
|
+
~~~
|
62
|
+
|
63
|
+
|
64
|
+
On the face of it, this is just a slightly different way of writing the same thing and you may or may not prefer
|
65
|
+
using the API vs. defining the hash directly.
|
66
|
+
|
67
|
+
However, the advantage of the API is that it allows the index to be defined out of order, allowing the user
|
68
|
+
to insert entries at specific points in the index table. This can be useful to allow plugins to add pages to
|
69
|
+
a parent application's guide section.
|
70
|
+
|
71
|
+
This is achieved by adding `:before` and `:after` options, here for example to add a new section before "Topic 1":
|
72
|
+
|
73
|
+
~~~ruby
|
74
|
+
index.section :topic0, heading: "Topic 0", before: :topic1 do |section|
|
75
|
+
section.page :my_topic
|
76
|
+
end
|
77
|
+
~~~
|
78
|
+
|
79
|
+
or to add a new page within the "Topic 1" section:
|
80
|
+
|
81
|
+
~~~ruby
|
82
|
+
index.section :topic1 do |section|
|
83
|
+
section.page :my_topic, heading: "My Heading", after: :item1
|
84
|
+
end
|
85
|
+
~~~
|
86
|
+
|
87
|
+
Note that both the `.section` and `.page` methods support the use of `:before` or `:after`.
|
88
|
+
|
89
|
+
If neither option is given when referencing an existing `GuideIndex` instance then the new section/page
|
90
|
+
will simply be appended onto the end.
|
46
91
|
|
47
92
|
### The Layout Helper
|
48
93
|
|
@@ -6,17 +6,17 @@ analytics: UA-64455560-1
|
|
6
6
|
|
7
7
|
%# Add/edit sections here, the code below will expand this with the correct markup,
|
8
8
|
%# pass in the topic you want selected via the :tab option.
|
9
|
-
%
|
10
|
-
%
|
11
|
-
% :intro
|
12
|
-
% :page2
|
13
|
-
%
|
14
|
-
%
|
15
|
-
% :
|
16
|
-
% :
|
17
|
-
%
|
9
|
+
% i = OrigenDocHelpers::GuideIndex.new
|
10
|
+
% i.section nil do |section|
|
11
|
+
% section.page :intro, heading: "Introduction"
|
12
|
+
% section.page :page2, heading: "Page 2"
|
13
|
+
% end
|
14
|
+
% i.section :topic1, heading: "Topic 1" do |section|
|
15
|
+
% section.page :item1, heading: "First Item"
|
16
|
+
% section.page :item2, heading: "Second Item"
|
17
|
+
% end
|
18
18
|
|
19
|
-
% render "templates/shared/searchable.html", options.merge(:index =>
|
19
|
+
% render "templates/shared/searchable.html", options.merge(:index => i, :root => "helpers/searchable") do
|
20
20
|
|
21
21
|
<%= yield %>
|
22
22
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: origen_doc_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen McGinty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: origen
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.7.15
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: origen_testers
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
description:
|
42
28
|
email:
|
43
29
|
- stephen.f.mcginty@gmail.com
|
@@ -45,6 +31,7 @@ executables: []
|
|
45
31
|
extensions: []
|
46
32
|
extra_rdoc_files: []
|
47
33
|
files:
|
34
|
+
- bin/fix_my_workspace
|
48
35
|
- config/application.rb
|
49
36
|
- config/boot.rb
|
50
37
|
- config/commands.rb
|
@@ -52,6 +39,7 @@ files:
|
|
52
39
|
- config/version.rb
|
53
40
|
- lib/origen_doc_helpers.rb
|
54
41
|
- lib/origen_doc_helpers/flow_page_generator.rb
|
42
|
+
- lib/origen_doc_helpers/guide_index.rb
|
55
43
|
- lib/origen_doc_helpers/helpers.rb
|
56
44
|
- lib/origen_doc_helpers/html_flow_formatter.rb
|
57
45
|
- lib/origen_doc_helpers/list_flow_formatter.rb
|
@@ -109,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
97
|
version: 1.8.11
|
110
98
|
requirements: []
|
111
99
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.6.
|
100
|
+
rubygems_version: 2.6.14.1
|
113
101
|
signing_key:
|
114
102
|
specification_version: 4
|
115
103
|
summary: Snippets and helpers for creating Origen web documents
|