yard-dash 1.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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzZjMGQ2YzVjN2VmYTliNGIzZWE4OGE4N2I1M2IyNTgwZDBiZTJiMg==
5
+ data.tar.gz: !binary |-
6
+ MmUxZDMzZWIxMzhmOWY4ZjRjMjllZDk0NTExNjhkYmU3NTNiMWIzOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OWFmNjZiODI1OWE0ZTY0MmNhZGY2MDA0OGQ4MjM2MmNlZTBmNDk3OGUwYTE3
10
+ YWMwM2FkMDViMGFmMWM2NWM1N2I2YjkwYjA2ODM4N2RhNTAzMWE3ZWVjMzk4
11
+ ODYwNTI3ZjVjYjBiM2M4NjBmNzg2NjA3NzU0YzFlM2YxNzY0MDI=
12
+ data.tar.gz: !binary |-
13
+ ZWFhZjJiZDYxMmRkMDUyZGJjNjk0Y2UwNWY0ZDUwOGUzMGQzNzBhOTUzMDI3
14
+ ZWYyN2ZkMTM2NWJiMDk4YzY0YWRjYTU2MWFiYmZmOTkwZWU0Y2ZiNDBmMmJl
15
+ YTZmYTZmN2E4Y2NiNjg2NDcyNWQ1ZDI3OTE0NmMwOTFiZjEzOTQ=
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # yard-dash
2
+
3
+ This `yard` plugin will generate a `Dash` **dockset** in addition to the normal HTML directory for a gem. The HTML code is copied from the standard yard source and is unchanged.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'yard-dash'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install yard-dash
20
+
21
+ ## Usage
22
+
23
+ Just run `yardoc` and the **dockset** will be created on top off the standard HTML tree.
24
+ The name of the gem inside **dockset** will be defined by the name inside the `gemspec` file.
25
+
26
+
@@ -0,0 +1,219 @@
1
+ include YARD
2
+ include Templates
3
+ require "sqlite3"
4
+
5
+ #
6
+ # Module YardDashHelper provides the logic to create the Dash
7
+ # docset.
8
+ #
9
+ # @author Fred Appelman <fred@appelman.net>
10
+ #
11
+ module YardDashHelper
12
+
13
+ # @return [String] The name of the subdirectory in the docset Documents
14
+ # directory
15
+ DOC_DIR = "docs"
16
+
17
+ # @return [String] The suffix for a dash docset
18
+ DOC_SET = ".docset"
19
+
20
+ # The tags found during scanning
21
+ @@docset_data = []
22
+
23
+ #
24
+ # Convert a name as return by the AST parser into a name
25
+ # suitable for the documentation.
26
+ # @example
27
+ # 'GemLogic.gem_lib_dir' => 'GemLogic'
28
+ # @example
29
+ # 'PidFile#release' => 'PidFile'
30
+ # @example
31
+ # 'XmlSimple::Cache#get_from_memory_cache' => 'XmlSimple/Cache'
32
+ #
33
+ # @param [<Yardoc class>,<Yardoc constant>, <Yardoc method>,
34
+ # <Yardoc module>] m The class/constant/method/module to convert
35
+ #
36
+ # @return [String] The converted name
37
+ #
38
+ def transpose(m)
39
+ base_name = m.to_s.gsub(%r{\..*$},"")
40
+ base_name = base_name.gsub(%r{#.*$},"")
41
+ base_name.gsub(%r[::],"/")
42
+ end
43
+ private :transpose
44
+
45
+
46
+ #
47
+ # Return the full HTML path given the class/constant/method or module m.
48
+ #
49
+ # @param [<Yardoc class>,<Yardoc constant>, <Yardoc method>,
50
+ # <Yardoc module>] m The class/constant/method/module to convert
51
+ #
52
+ # @return [String] The full path
53
+ #
54
+ def html_path(m)
55
+ base_name = transpose(m)
56
+ "#{DOC_DIR}/" + base_name + ".html"
57
+ end
58
+ private :html_path
59
+
60
+ #
61
+ # Return the readable name for the supplied class/constant/method
62
+ # or module m.
63
+ #
64
+ # @param [<Yardoc class>,<Yardoc constant>, <Yardoc method>,
65
+ # <Yardoc module>] m The class/constant/method/module to convert
66
+ #
67
+ # @return [String] The readable path
68
+ #
69
+ def name(m)
70
+ case m.scope
71
+ when :instance
72
+ m.to_s.sub(%r{#([^#]*?)$},'.\1')
73
+ when :class
74
+ m.to_s
75
+ else
76
+ abort("Scope: #{m.scope} unknown")
77
+ end
78
+ end
79
+ private :name
80
+
81
+ # Called by the ERB to process all methods in the Registry.
82
+ #
83
+ # @return [void]
84
+ #
85
+ def all_methods
86
+ Registry.all(:method).map do |m|
87
+ t = if m.to_s.match(/^#/)
88
+ # Top level namespace
89
+ [name(m), "Method", "#{DOC_DIR}/top-level-namespace.html" + '#' + "#{m.name}-#{m.scope}_method"]
90
+ else
91
+ [name(m), "Method", html_path(m) + '#' + "#{m.name}-#{m.scope}_method"]
92
+ end
93
+ @@docset_data << t unless @@docset_data.include?(t)
94
+ end
95
+ end
96
+ private :all_methods
97
+
98
+
99
+ # Called by the ERB to process all classes in the Registry.
100
+ #
101
+ # @return [void]
102
+ #
103
+ def all_classes
104
+ Registry.all(:class).map do |m|
105
+ t = [m.to_s, "Class", html_path(m)]
106
+ @@docset_data << t unless @@docset_data.include?(t)
107
+ end
108
+ end
109
+ private :all_classes
110
+
111
+ # Called by the ERB to process all modules in the Registry.
112
+ #
113
+ # @return [void]
114
+ #
115
+ def all_modules
116
+ Registry.all(:module).map do |m|
117
+ t = [m.to_s, "Module", html_path(m)]
118
+ @@docset_data << t unless @@docset_data.include?(t)
119
+ end
120
+ end
121
+ private :all_modules
122
+
123
+ # Called by the ERB to process all constants in the Registry.
124
+ #
125
+ # @return [void]
126
+ #
127
+ def all_constants
128
+ Registry.all(:constant).map do |m|
129
+ # This is an example of a constant:
130
+ # Vlogger::Severity::SEVERITY_TO_COLOR
131
+ # The name of the constant is as above. The name of the file
132
+ # is the Vlogger/Severity.html
133
+ t = [m.to_s, "Constant", "#{DOC_DIR}/" + transpose(m).sub(%r{/[^/]*?$},"") + ".html"]
134
+ @@docset_data << t unless @@docset_data.include?(t)
135
+ end
136
+ end
137
+ private :all_constants
138
+
139
+ #
140
+ # Return a plist as a string
141
+ #
142
+ # @param [String] package The name of the package
143
+ #
144
+ # @return [String] The plist
145
+ #
146
+ def plist(package)
147
+ <<-XML
148
+ <?xml version="1.0" encoding="UTF-8"?>
149
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
150
+ <plist version="1.0">
151
+ <dict>
152
+ <key>CFBundleIdentifier</key>
153
+ <string>#{package}</string>
154
+ <key>CFBundleName</key>
155
+ <string>#{package}</string>
156
+ <key>DocSetPlatformFamily</key>
157
+ <string>ruby</string>
158
+ <key>isDashDocset</key>
159
+ <true/>
160
+ </dict>
161
+ </plist>
162
+ XML
163
+ end
164
+ private :plist
165
+
166
+ #
167
+ # Write the docset
168
+ #
169
+ # @return [void]
170
+ #
171
+ def write_docset
172
+ gemspecs = Dir[%q{*.gemspec}]
173
+ abort("Cannot find gemspec file") if gemspecs.size == 0
174
+ abort("Too many gemspec files ") if gemspecs.size > 1
175
+ package = gemspecs.shift.gsub(".gemspec",'')
176
+ target = package + ".docset"
177
+ # Remove the previous content
178
+ FileUtils.rm_rf(target) if Dir.exist?(target)
179
+ # Create the docset
180
+ FileUtils.mkdir_p(target)
181
+ FileUtils.mkdir_p(target + '/' + 'Contents/Resources/Documents/')
182
+ # Create Info.plist file
183
+ plist = plist(package)
184
+ File.open(target + '/Contents/Info.plist', 'w+') { |file| file.write plist }
185
+ # Copy the doc directory
186
+ new_doc_path = target + '/Contents/Resources/Documents/'
187
+ FileUtils.cp_r "doc", new_doc_path
188
+ FileUtils.mv File.join(new_doc_path,"doc"), File.join(new_doc_path,"docs")
189
+ # Create the database
190
+ @db = SQLite3::Database.new(target + '/Contents/Resources/docSet.dsidx')
191
+ @db.execute('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT)')
192
+ @db.execute('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path)')
193
+ # Add the methods, classes, modules and constants
194
+ @@docset_data.each do |docset_element|
195
+ @db.execute("insert into searchIndex (name, type, path) VALUES(?, ?, ?)",*docset_element)
196
+ end
197
+ end
198
+ private :write_docset
199
+
200
+
201
+ #
202
+ # Process all constants, classes, methods and modules and
203
+ # write the docset.
204
+ #
205
+ # @return [<type>] <description>
206
+ #
207
+ def do_dash
208
+ all_constants
209
+ all_classes
210
+ all_methods
211
+ all_modules
212
+ write_docset
213
+ end
214
+
215
+ end
216
+
217
+
218
+
219
+
@@ -0,0 +1,58 @@
1
+ require "tmpdir"
2
+
3
+ #
4
+ # Module YardDashSetup provides the setup logic for yard-dash
5
+ #
6
+ # @author Fred Appelman <fred@appelman.net>
7
+ #
8
+ module YardDashSetup
9
+ module_function
10
+
11
+ #
12
+ # @return [String] The file in the yad package that needs patching
13
+ ERB = 'full_list.erb'
14
+
15
+ #
16
+ # Create a temporary directory. This directory is constant
17
+ # during a run and is removed when the application exits.
18
+ #
19
+ #
20
+ # @return [String] The name of the created directory
21
+ #
22
+ def tmpdir
23
+ @tmpdir ||= begin
24
+ Dir.mktmpdir
25
+ end
26
+ end
27
+
28
+
29
+ #
30
+ # Setup the override of the erb file. We copy one file from
31
+ # the standard yard directory and copy that file to a temporary
32
+ # directory after which the copied file is patched. A few hooks
33
+ # that trigger the logic in the base_helper file.
34
+ #
35
+ #
36
+ # @return [void]
37
+ #
38
+ def setup_override
39
+ spec = Gem::Specification.find_by_name 'yard'
40
+ erb = File.join(spec.gem_dir,"templates","default","fulldoc","html",ERB)
41
+ # Create the subdirectory structure
42
+ subdir = File.join(tmpdir,"default","fulldoc","html")
43
+ FileUtils.mkdir_p subdir
44
+ # Copy the erb
45
+ target_file = File.join(subdir,ERB)
46
+ FileUtils.cp(erb,target_file)
47
+ # Open the file and add the anchors
48
+ open(target_file,'a') do |file|
49
+ file.write "<% do_dash %>\n"
50
+ end
51
+ end
52
+
53
+ # Remove the directory at the end of the run
54
+ END {
55
+ # Remove the temp directory
56
+ FileUtils.rm_rf tmpdir
57
+ }
58
+ end
@@ -0,0 +1,11 @@
1
+ #
2
+ # Module Yard-dashVersion provides a version number
3
+ # for the application 'yard-dash''
4
+ #
5
+ # @author Fred Appelman <fred@appelman.net>
6
+ #
7
+ module YardDashVersion
8
+ #
9
+ # @return [String] The application version number
10
+ NUMBER = "1.0"
11
+ end
data/lib/yard-dash.rb ADDED
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ require "yard-dash/setup"
4
+ require "yard-dash/base_helper"
5
+ require "yard-dash/version"
6
+
7
+ # Setup the yard-dash override directory
8
+ YardDashSetup::setup_override
9
+ # Add the template helper
10
+ Template.extra_includes << YardDashHelper
11
+ # Override the default template for the given file
12
+ YARD::Templates::Engine.register_template_path YardDashSetup::tmpdir
13
+
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-dash
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Fred Appelman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Yard-dash generates a docset for Dash
14
+ email: fred@appelman.net
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/yard-dash.rb
21
+ - lib/yard-dash/base_helper.rb
22
+ - lib/yard-dash/setup.rb
23
+ - lib/yard-dash/version.rb
24
+ homepage: http://fred.appelman.net
25
+ licenses:
26
+ - (c) Fred Appelman
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.4.4
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Generate beside the standard HTML documentation a docset to be used by Dash
48
+ from the standard yard inline documentation.
49
+ test_files: []
50
+ has_rdoc: false