doc_to_dash 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in doc_to_dash.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Caleb Mingle
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # DocToDash
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'doc_to_dash'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install doc_to_dash
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'doc_to_dash/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "doc_to_dash"
8
+ gem.version = DocToDash::VERSION
9
+ gem.authors = ["Caleb Mingle"]
10
+ gem.email = ["me@caleb.io"]
11
+ gem.description = "Converts documentation to a Dash Docset"
12
+ gem.summary = "Documentation to Dash Docset Converter"
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "nokogiri"
21
+ gem.add_dependency "sqlite3"
22
+ end
@@ -0,0 +1,3 @@
1
+ module DocToDash
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,39 @@
1
+ module DocToDash
2
+ class YardParser
3
+ def initialize(doc_directory)
4
+ @doc_directory = doc_directory
5
+ end
6
+
7
+ def parse_methods
8
+ classes_file = File.read(@doc_directory + '/class_list.html')
9
+ classes_html = Nokogiri::HTML(classes_file)
10
+ classes = []
11
+
12
+ classes_html.xpath('//li').children.select{|c| c.name == "span"}.each do |method|
13
+ a = method.children.first
14
+ title = a.children.first.to_s.gsub('#', '')
15
+ href = a["href"].to_s
16
+
17
+ classes << [href, title] unless title == "Top Level Namespace"
18
+ end
19
+
20
+ classes
21
+ end
22
+
23
+ def parse_classes
24
+ methods_file = File.read(@doc_directory + '/method_list.html')
25
+ methods_html = Nokogiri::HTML(methods_file)
26
+ methods = []
27
+
28
+ methods_html.xpath('//li').children.select{|c| c.name == "span"}.each do |method|
29
+ a = method.children.first
30
+ href = a["href"].to_s
31
+ name = a["title"].to_s.gsub(/\((.+)\)/, '').strip! # Strip the (ClassName) and whitespace.
32
+
33
+ methods << [href, name]
34
+ end
35
+
36
+ methods
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,145 @@
1
+ require "doc_to_dash/version"
2
+ require "doc_to_dash/yard_parser"
3
+ require 'sqlite3'
4
+ require 'fileutils'
5
+ require 'nokogiri'
6
+
7
+ module DocToDash
8
+ class DocsetGenerator
9
+ def initialize(options = {})
10
+ @classes = []
11
+ @methods = []
12
+
13
+ @options = {
14
+ :docset_name => 'DefaultDocset',
15
+ :docset_output_path => 'doc/', # This is where the actual package will be created.
16
+ :docset_output_filename => lambda {@options[:docset_name] + '.docset' },
17
+ :icon_path => nil, # This is the docset icon that never changes, if you want a default icon just set this to nil.
18
+ :doc_input_path => nil, # This is the actual docs to copy over to the Docset.
19
+ :doc_save_folder => 'docs', # This is the directory name it will store under /Contents/Resources/Documents/{this}
20
+ :verbose => true,
21
+ :parser => DocToDash::YardParser
22
+ }.merge(options)
23
+
24
+ @docset_path = File.expand_path(@options[:docset_output_path]) + '/' + @options[:docset_output_filename].call
25
+ @doc_directory = @docset_path + '/Contents/Resources/Documents/' + @options[:doc_save_folder]
26
+ end
27
+
28
+ def run
29
+ log "Beginning to generate Dash Docset."
30
+
31
+ unless check_and_format_options
32
+ log "Error: " + @error # There was an error of some sort..
33
+ return false
34
+ end
35
+
36
+ clean_up_files
37
+ create_structure
38
+ copy_default_files
39
+ copy_docs_to_docset
40
+
41
+ create_database
42
+
43
+ parser = @options[:parser].new(@doc_directory)
44
+
45
+ @classes = parser.parse_classes
46
+ @methods = parser.parse_methods
47
+
48
+ load_methods_into_database
49
+ load_classes_into_database
50
+
51
+ log "Docset created."
52
+
53
+ @docset_path
54
+ end
55
+
56
+ private
57
+
58
+ def log(message)
59
+ puts "=> #{message}" if @options[:verbose]
60
+ end
61
+
62
+ def check_and_format_options
63
+ if @options[:doc_input_path].nil?
64
+ @error = "You must provide a path to your docs. (:doc_input_path)"
65
+ return false
66
+ end
67
+
68
+ if @options[:doc_save_folder].nil?
69
+ @error = "You must provide a doc_path_name for us to save under. (:doc_save_folder)"
70
+ return false
71
+ end
72
+
73
+ @options[:doc_input_path] = File.expand_path(@options[:doc_input_path])
74
+
75
+ true
76
+ end
77
+
78
+ def clean_up_files
79
+ log "Removing old Docset."
80
+ FileUtils.rm_rf(@docset_path) if Dir.exist?(@docset_path)
81
+ end
82
+
83
+ def create_structure
84
+ log "Creating new Docset structure."
85
+
86
+ FileUtils.mkdir_p(@docset_path)
87
+ FileUtils.mkdir_p(@docset_path + '/' + 'Contents/Resources/Documents/')
88
+ end
89
+
90
+ def copy_default_files
91
+ log "Copy default Docset files over."
92
+
93
+ FileUtils.cp @options[:icon_path], @docset_path + '/' unless @options[:icon_path].nil?
94
+ File.open(@docset_path + '/Contents/Info.plist', 'w+') { |file| file.write(default_plist.gsub('{DOCSET_NAME}', @options[:docset_name])) }
95
+ end
96
+
97
+ def copy_docs_to_docset
98
+ log "Copying documentation to Docset."
99
+
100
+ new_doc_path = @docset_path + '/Contents/Resources/Documents/'
101
+ FileUtils.cp_r @options[:doc_input_path], new_doc_path
102
+ FileUtils.mv new_doc_path + File.basename(@options[:doc_input_path]), new_doc_path + @options[:doc_save_folder]
103
+ end
104
+
105
+ def create_database
106
+ log "Creating Docset index database."
107
+
108
+ @db = SQLite3::Database.new(@docset_path + '/Contents/Resources/docSet.dsidx')
109
+ @db.execute('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT)')
110
+ end
111
+
112
+ def load_methods_into_database
113
+ log "Loading methods into database."
114
+ insert_into_database @methods, 'clm'
115
+ end
116
+
117
+ def load_classes_into_database
118
+ log "Loading classes into database."
119
+ insert_into_database @classes, 'cl'
120
+ end
121
+
122
+ def insert_into_database(array, type)
123
+ array.each { |item| @db.execute("insert into searchIndex (name, type, path) VALUES(?, ?, ?)", item.last, type, @options[:doc_save_folder] + '/' + item.first) }
124
+ end
125
+
126
+ def default_plist
127
+ return <<XML
128
+ <?xml version="1.0" encoding="UTF-8"?>
129
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
130
+ <plist version="1.0">
131
+ <dict>
132
+ <key>CFBundleIdentifier</key>
133
+ <string>{DOCSET_NAME}</string>
134
+ <key>CFBundleName</key>
135
+ <string>{DOCSET_NAME}</string>
136
+ <key>DocSetPlatformFamily</key>
137
+ <string>{DOCSET_NAME}</string>
138
+ <key>isDashDocset</key>
139
+ <true/>
140
+ </dict>
141
+ </plist>
142
+ XML
143
+ end
144
+ end
145
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doc_to_dash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Caleb Mingle
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Converts documentation to a Dash Docset
47
+ email:
48
+ - me@caleb.io
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - doc_to_dash.gemspec
59
+ - lib/doc_to_dash.rb
60
+ - lib/doc_to_dash/version.rb
61
+ - lib/doc_to_dash/yard_parser.rb
62
+ homepage: ''
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Documentation to Dash Docset Converter
86
+ test_files: []