hologram 0.5.2
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 +7 -0
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +154 -0
- data/Rakefile +1 -0
- data/hologram.gemspec +27 -0
- data/lib/hologram.rb +319 -0
- data/lib/hologram/version.rb +29 -0
- data/lib/hologram_markdown_renderer.rb +41 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e4adec839d8a6a2ae3bdb51fad49eae23e42cf6
|
4
|
+
data.tar.gz: c49899ab9a578374192073286465bdba4a23f340
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80c5363bd1fef75a8547075b37a933bacf209f65e77896898ebb2d7105dcbe22f3c229a094879c4857fa14d9a69e7fbf6f19ee9145abd26a1b47d73dea6cda20
|
7
|
+
data.tar.gz: 9ba3a7facb16ba43a823fcc4d797e8ce95ad824c9a860470b5e065fd8b5a7e57240a8e16ba4d66925724610f70ea6fdad2a2901acc769a83dd8596154c3e6e58
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
+
.sass-cache
|
19
|
+
build
|
20
|
+
bin
|
21
|
+
!bin/hologram
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2013, Trulia, Inc.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
# Hologram
|
2
|
+
|
3
|
+
Hologram is a Ruby gem that parses comments in your CSS and turns them into a beautiful style guide.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'hologram'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
If you don't use bundler you can run `gem install hologram`.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
There are two things you need to do to start using hologram:
|
20
|
+
|
21
|
+
1. Create a YAML config file for your project
|
22
|
+
|
23
|
+
2. Document yourself some code
|
24
|
+
|
25
|
+
### Creating a YAML config file
|
26
|
+
|
27
|
+
Hologram needs a few configuration settings before it can begin to build
|
28
|
+
your documentation for you. Once this is set up you can execute hologram by
|
29
|
+
simply running:
|
30
|
+
|
31
|
+
`hologram path/to/your/config.yml` or (using bundler) `bundle exec hologram path/to/your/config.yml`
|
32
|
+
|
33
|
+
Your config file needs to contain the following key/value pairs
|
34
|
+
|
35
|
+
* **source**: relative path to your source files
|
36
|
+
|
37
|
+
* **destination**: relative path to where you want the documentation to be
|
38
|
+
built to
|
39
|
+
|
40
|
+
* **documentation_assets**: The path that contains supporting assets for
|
41
|
+
the documentaiton page. This typically includes html fragments (header/footer, etc),
|
42
|
+
styleguide specific CSS, javascript and any images.
|
43
|
+
|
44
|
+
* **custom_markdown**: (optional) this is the filename of a class that extends
|
45
|
+
RedCarpet::Render::HTML class. Use this for when you need
|
46
|
+
additional classes or html tags for different parts of the page.
|
47
|
+
|
48
|
+
* **dependencies**: a **list** of relative pathes to a folderes containing any dependencies your style guide has.
|
49
|
+
These folders will be copied over into the documentation output directory.
|
50
|
+
PUT THE CSS/JS THAT IS ACTUALLY BEING DOCUMENTED HERE
|
51
|
+
|
52
|
+
##### Example config file
|
53
|
+
|
54
|
+
# The directory containing the source files to parse
|
55
|
+
source: ../components
|
56
|
+
|
57
|
+
# The directory that hologram will build to
|
58
|
+
destination: ../docs
|
59
|
+
|
60
|
+
# The assets needed to build/style the docs (includes header.html, footer.html, etc)
|
61
|
+
documentation_assets: ../hologram_assets
|
62
|
+
|
63
|
+
# A custom markdown renderer that extends `RedCarpet::Render::HTML class`
|
64
|
+
custom_markdown: trulia_markdown_renderer.rb
|
65
|
+
|
66
|
+
# Any other asset folders that need to be copied to the destination folder
|
67
|
+
# This is where the CSS/JS you are actually documenting should go
|
68
|
+
dependencies:
|
69
|
+
- ../build
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
###Documenting your styles
|
74
|
+
|
75
|
+
Hologram will scan any css/scss/less files within your **source** directory.
|
76
|
+
It will look for comments that match the following:
|
77
|
+
|
78
|
+
/*doc
|
79
|
+
---
|
80
|
+
title: Buttons
|
81
|
+
name: button
|
82
|
+
category: Base CSS
|
83
|
+
---
|
84
|
+
|
85
|
+
Button styles can be applied to any element. Typically you'll want
|
86
|
+
to use either a `<button>` or an `<a>` element:
|
87
|
+
|
88
|
+
```html_example
|
89
|
+
<button class="btn btnDefault">Click</button>
|
90
|
+
<a class="btn btnDefault" href="trulia.com">Trulia!</a>
|
91
|
+
```
|
92
|
+
|
93
|
+
If your button is actually a link to another page, please use the
|
94
|
+
`<a>` element, while if your button performs an action, such as
|
95
|
+
submitting a form or triggering some javascript event, then use a
|
96
|
+
`<button>` element.
|
97
|
+
|
98
|
+
*/
|
99
|
+
|
100
|
+
The first section of the comment is a yaml block that defines certain
|
101
|
+
aspects of the this documentation block. The second part is simply
|
102
|
+
markdown as defined by Redcarpet.
|
103
|
+
|
104
|
+
####Document YAML section
|
105
|
+
The yaml in the doc block can have any key value pair you deem important
|
106
|
+
but it specifically looks for the following keys:
|
107
|
+
|
108
|
+
* **title**: The title to display in the documents
|
109
|
+
* **category**: This is the broad category for the component, all
|
110
|
+
components in the same category will be written to the same page.
|
111
|
+
(Usually named the same as the category but with spaces replaced with
|
112
|
+
underscores and lower cased).
|
113
|
+
* **name**: This is used for grouping components, by assigning
|
114
|
+
a name a component can be referenced in another component as a parent.
|
115
|
+
* **parent**: Optional. If this is set the current component will be
|
116
|
+
displayed as a section within the parent's documentation.
|
117
|
+
|
118
|
+
|
119
|
+
###Documentation Assets
|
120
|
+
|
121
|
+
The documentation assets folder contains the html, css, js and images
|
122
|
+
you'll need for making your style guide look beautiful.
|
123
|
+
|
124
|
+
Hologram doesn't care too much about to what is in here as it is intended
|
125
|
+
to be custom for your style guide.
|
126
|
+
|
127
|
+
However, it does look for two files called header.html and footer.html.
|
128
|
+
These are html fragments that will be used when creating a new category page.
|
129
|
+
`header.html` will be copied to the beginning to the page and `footer.html`
|
130
|
+
will be copied to the bottom of the page. This gives you control of how you
|
131
|
+
will navigate your docs and lets you include any css, disclaimer text, and
|
132
|
+
whatever else you need on each page.
|
133
|
+
|
134
|
+
#####Styling Your Code Examples
|
135
|
+
|
136
|
+
Hologram uses [pygments.rb](https://github.com/tmm1/pygments.rb) gem to provide
|
137
|
+
syntax highlighting for code examples. One of the assets that you probably want
|
138
|
+
to include in your documentation assets folder is a css file that styles the
|
139
|
+
"pygmentized" code examples. We use `github.css` which can be found along with the
|
140
|
+
css we use to style code blocks [here](https://github.com/trulia/hologram-example/tree/gh-pages/hologram_assets/doc_assets/css).
|
141
|
+
|
142
|
+
## Contributing
|
143
|
+
|
144
|
+
1. Fork it
|
145
|
+
2. Create your feature/bug fix branch (`git checkout -b my-new-feature`)
|
146
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
147
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
148
|
+
5. Create new Pull Request
|
149
|
+
|
150
|
+
|
151
|
+
## License
|
152
|
+
[Hologram is licensed under the MIT License](https://github.com/trulia/hologram/blob/master/LICENSE.txt)
|
153
|
+
|
154
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/hologram.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hologram/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hologram"
|
8
|
+
spec.version = Hologram::VERSION
|
9
|
+
spec.authors = ["JD Cantrell", "August Flanagan"]
|
10
|
+
spec.email = ["jcantrell@trulia.com"]
|
11
|
+
spec.description = %q{Build doc type things}
|
12
|
+
spec.summary = %q{Build document type things.}
|
13
|
+
spec.homepage = "http://trulia.github.io/hologram"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.add_dependency "redcarpet", "~> 2.2.2"
|
17
|
+
spec.add_dependency "sass", "~> 3.2.7"
|
18
|
+
spec.add_dependency "pygments.rb", "~> 0.4.2"
|
19
|
+
|
20
|
+
spec.files = `git ls-files`.split($/)
|
21
|
+
spec.executables = ['hologram']
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
data/lib/hologram.rb
ADDED
@@ -0,0 +1,319 @@
|
|
1
|
+
# Copyright (c) 2013, Trulia, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
# * Redistributions of source code must retain the above copyright
|
7
|
+
# notice, this list of conditions and the following disclaimer.
|
8
|
+
# * Redistributions in binary form must reproduce the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer in the
|
10
|
+
# documentation and/or other materials provided with the distribution.
|
11
|
+
# * Neither the name of the Trulia, Inc. nor the
|
12
|
+
# names of its contributors may be used to endorse or promote products
|
13
|
+
# derived from this software without specific prior written permission.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
16
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
17
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
18
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TRULIA, INC. BE
|
19
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
20
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
21
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
22
|
+
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
23
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
24
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
25
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
|
27
|
+
require "hologram/version"
|
28
|
+
|
29
|
+
require 'redcarpet'
|
30
|
+
require 'yaml'
|
31
|
+
require 'pygments'
|
32
|
+
require 'fileutils'
|
33
|
+
require 'pathname'
|
34
|
+
|
35
|
+
require 'hologram_markdown_renderer'
|
36
|
+
|
37
|
+
module Hologram
|
38
|
+
|
39
|
+
|
40
|
+
class DocumentBlock
|
41
|
+
attr_accessor :name, :parent, :children, :title, :category, :markdown, :output_file, :config
|
42
|
+
|
43
|
+
def initialize(config = nil, markdown = nil)
|
44
|
+
@children = {}
|
45
|
+
set_members(config, markdown) if config and markdown
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_members(config, markdown)
|
49
|
+
@name = config['name']
|
50
|
+
@parent = config['parent']
|
51
|
+
@category = config['category']
|
52
|
+
@title = config['title']
|
53
|
+
@markdown = markdown
|
54
|
+
end
|
55
|
+
|
56
|
+
def is_valid?
|
57
|
+
@name && @markdown
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
class Builder
|
63
|
+
attr_accessor :doc_blocks, :config, :pages
|
64
|
+
|
65
|
+
def init(args)
|
66
|
+
@doc_blocks, @pages = {}, {}
|
67
|
+
begin
|
68
|
+
@config = args ? YAML::load_file(args[0]) : YAML::load_file('hologram_config.yml')
|
69
|
+
validate_config
|
70
|
+
|
71
|
+
#TODO: maybe this should move into build_docs
|
72
|
+
current_path = Dir.pwd
|
73
|
+
base_path = Pathname.new(args[0])
|
74
|
+
Dir.chdir(base_path.dirname)
|
75
|
+
|
76
|
+
build_docs
|
77
|
+
|
78
|
+
Dir.chdir(current_path)
|
79
|
+
puts "Build successful. (-: ".green
|
80
|
+
rescue Errno::ENOENT
|
81
|
+
display_error("Could not load config file.")
|
82
|
+
rescue RuntimeError => e
|
83
|
+
display_error("#{e}")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
private
|
89
|
+
def build_docs
|
90
|
+
# Create the output directory if it doesn't exist
|
91
|
+
FileUtils.mkdir_p(config['destination']) unless File.directory?(config['destination'])
|
92
|
+
|
93
|
+
input_directory = Pathname.new(config['source']).realpath
|
94
|
+
output_directory = Pathname.new(config['destination']).realpath
|
95
|
+
doc_assets = Pathname.new(config['documentation_assets']).realpath
|
96
|
+
|
97
|
+
process_dir(input_directory)
|
98
|
+
|
99
|
+
build_pages_from_doc_blocks(@doc_blocks)
|
100
|
+
write_docs(output_directory, doc_assets)
|
101
|
+
|
102
|
+
# Copy over dependencies
|
103
|
+
if config['dependencies']
|
104
|
+
config['dependencies'].each do |dir|
|
105
|
+
dirpath = Pathname.new(dir).realpath
|
106
|
+
if Dir.exists?("#{dir}")
|
107
|
+
`rm -rf #{output_directory}/#{dirpath.basename}`
|
108
|
+
`cp -R #{dirpath} #{output_directory}/#{dirpath.basename}`
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
Dir.foreach(doc_assets) do |item|
|
114
|
+
# ignore . and .. directories
|
115
|
+
next if item == '.' or item == '..'
|
116
|
+
`rm -rf #{output_directory}/#{item}`
|
117
|
+
`cp -R #{doc_assets}/#{item} #{output_directory}/#{item}`
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def process_dir(base_directory)
|
123
|
+
#get all directories in our library folder
|
124
|
+
directories = Dir.glob("#{base_directory}/**/*/")
|
125
|
+
directories.unshift(base_directory)
|
126
|
+
|
127
|
+
directories.each do |directory|
|
128
|
+
# filter and sort the files in our directory
|
129
|
+
files = []
|
130
|
+
Dir.foreach(directory).select{ |file| is_supported_file_type?(file) }.each do |file|
|
131
|
+
files << file
|
132
|
+
end
|
133
|
+
files.sort!
|
134
|
+
process_files(files, directory)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
def process_files(files, directory)
|
140
|
+
files.each do |input_file|
|
141
|
+
if input_file.end_with?('md')
|
142
|
+
@pages[File.basename(input_file, '.md') + '.html'] = File.read("#{directory}/#{input_file}")
|
143
|
+
else
|
144
|
+
process_file("#{directory}/#{input_file}")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
def process_file(file)
|
151
|
+
file_str = File.read(file)
|
152
|
+
# get any comment blocks that match the pattern /*doc ... */
|
153
|
+
hologram_comments = file_str.scan(/^\s*\/\*doc(.*?)\*\//m)
|
154
|
+
return unless hologram_comments
|
155
|
+
|
156
|
+
hologram_comments.each do |comment_block|
|
157
|
+
doc_block = build_doc_block(comment_block[0])
|
158
|
+
add_doc_block_to_collection(doc_block) if doc_block
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
# this should throw an error if we have a match, but now yaml_match
|
164
|
+
def build_doc_block(comment_block)
|
165
|
+
yaml_match = /^\s*---\s(.*?)\s---$/m.match(comment_block)
|
166
|
+
return unless yaml_match
|
167
|
+
markdown = comment_block.sub(yaml_match[0], '')
|
168
|
+
config = YAML::load(yaml_match[0])
|
169
|
+
if config['name'].nil?
|
170
|
+
puts "Missing required name config value. This hologram comment will be skipped. \n #{config.inspect}"
|
171
|
+
else
|
172
|
+
doc_block = DocumentBlock.new(config, markdown)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
def add_doc_block_to_collection(doc_block)
|
178
|
+
return unless doc_block.is_valid?
|
179
|
+
if doc_block.parent.nil?
|
180
|
+
#parent file
|
181
|
+
begin
|
182
|
+
doc_block.output_file = get_file_name(doc_block.category)
|
183
|
+
rescue NoMethodError => e
|
184
|
+
display_error("No output file specified. Missing category? \n #{doc_block.inspect}")
|
185
|
+
end
|
186
|
+
|
187
|
+
@doc_blocks[doc_block.name] = doc_block;
|
188
|
+
doc_block.markdown = "\n\n# #{doc_block.title}" + doc_block.markdown
|
189
|
+
else
|
190
|
+
# child file
|
191
|
+
parent_doc_block = @doc_blocks[doc_block.parent]
|
192
|
+
if parent_doc_block
|
193
|
+
doc_block.markdown = "\n\n## #{doc_block.title}" + doc_block.markdown
|
194
|
+
parent_doc_block.children[doc_block.name] = doc_block
|
195
|
+
else
|
196
|
+
@doc_blocks[doc_block.parent] = DocumentBlock.new()
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
def build_pages_from_doc_blocks(doc_blocks, output_file = nil)
|
203
|
+
doc_blocks.sort.map do |key, doc_block|
|
204
|
+
output_file = doc_block.output_file || output_file
|
205
|
+
@pages[output_file] ||= ""
|
206
|
+
@pages[output_file] << doc_block.markdown
|
207
|
+
if doc_block.children
|
208
|
+
build_pages_from_doc_blocks(doc_block.children, output_file)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
def write_docs(output_directory, doc_assets)
|
215
|
+
# load the markdown renderer we are going to use
|
216
|
+
renderer = get_markdown_renderer
|
217
|
+
|
218
|
+
#generate html from markdown
|
219
|
+
@pages.each do |file_name, markdown|
|
220
|
+
fh = get_fh(output_directory, file_name)
|
221
|
+
|
222
|
+
# generate doc nav html
|
223
|
+
if File.exists?("#{doc_assets}/header.html")
|
224
|
+
fh.write(File.read("#{doc_assets}/header.html"))
|
225
|
+
end
|
226
|
+
|
227
|
+
# write the docs
|
228
|
+
fh.write(renderer.render(markdown))
|
229
|
+
|
230
|
+
# write the footer
|
231
|
+
if File.exists?("#{doc_assets}/footer.html")
|
232
|
+
fh.write(File.read("#{doc_assets}/footer.html"))
|
233
|
+
end
|
234
|
+
fh.close()
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
def get_markdown_renderer
|
240
|
+
if config['custom_markdown'].nil?
|
241
|
+
renderer = Redcarpet::Markdown.new(HologramMarkdownRenderer, { :fenced_code_blocks => true, :tables => true })
|
242
|
+
else
|
243
|
+
begin
|
244
|
+
load config['custom_markdown']
|
245
|
+
renderer_class = File.basename(config['custom_markdown'], '.rb').split(/_/).map(&:capitalize).join
|
246
|
+
puts "Custom markdown renderer #{renderer_class} loaded."
|
247
|
+
renderer = Redcarpet::Markdown.new(Module.const_get(renderer_class), { :fenced_code_blocks => true, :tables => true })
|
248
|
+
rescue LoadError => e
|
249
|
+
display_error("Could not load #{config['custom_markdown']}.")
|
250
|
+
rescue NameError => e
|
251
|
+
display_error("Class #{renderer_class} not found in #{config['custom_markdown']}.")
|
252
|
+
end
|
253
|
+
end
|
254
|
+
renderer
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
def validate_config
|
259
|
+
unless @config.key?('source')
|
260
|
+
raise "No source directory specified in the config file"
|
261
|
+
end
|
262
|
+
|
263
|
+
unless @config.key?('destination')
|
264
|
+
raise "No destination directory specified in the config"
|
265
|
+
end
|
266
|
+
|
267
|
+
unless @config.key?('documentation_assets')
|
268
|
+
raise "No documentation assets directory specified"
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
|
273
|
+
def is_supported_file_type?(file)
|
274
|
+
supported_extensions = ['.css', '.scss', '.less', '.sass', '.js', '.md', '.markdown' ]
|
275
|
+
supported_extensions.include?(File.extname(file))
|
276
|
+
end
|
277
|
+
|
278
|
+
def display_error(message)
|
279
|
+
puts "(\u{256F}\u{00B0}\u{25A1}\u{00B0}\u{FF09}\u{256F}".green + "\u{FE35} \u{253B}\u{2501}\u{253B} ".yellow + " Build not complete.".red
|
280
|
+
puts " #{message}"
|
281
|
+
exit 1
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
def get_file_name(str)
|
286
|
+
str = str.gsub(' ', '_').downcase + '.html'
|
287
|
+
end
|
288
|
+
|
289
|
+
|
290
|
+
def get_fh(output_directory, output_file)
|
291
|
+
File.open("#{output_directory}/#{output_file}", 'w')
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
|
298
|
+
class String
|
299
|
+
# colorization
|
300
|
+
def colorize(color_code)
|
301
|
+
"\e[#{color_code}m#{self}\e[0m"
|
302
|
+
end
|
303
|
+
|
304
|
+
def red
|
305
|
+
colorize(31)
|
306
|
+
end
|
307
|
+
|
308
|
+
def green
|
309
|
+
colorize(32)
|
310
|
+
end
|
311
|
+
|
312
|
+
def yellow
|
313
|
+
colorize(33)
|
314
|
+
end
|
315
|
+
|
316
|
+
def pink
|
317
|
+
colorize(35)
|
318
|
+
end
|
319
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Copyright (c) 2013, Trulia, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
# * Redistributions of source code must retain the above copyright
|
7
|
+
# notice, this list of conditions and the following disclaimer.
|
8
|
+
# * Redistributions in binary form must reproduce the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer in the
|
10
|
+
# documentation and/or other materials provided with the distribution.
|
11
|
+
# * Neither the name of the Trulia, Inc. nor the
|
12
|
+
# names of its contributors may be used to endorse or promote products
|
13
|
+
# derived from this software without specific prior written permission.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
16
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
17
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
18
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TRULIA, INC. BE
|
19
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
20
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
21
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
22
|
+
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
23
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
24
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
25
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
|
27
|
+
module Hologram
|
28
|
+
VERSION = "0.5.2"
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Copyright (c) 2013, Trulia, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
# * Redistributions of source code must retain the above copyright
|
7
|
+
# notice, this list of conditions and the following disclaimer.
|
8
|
+
# * Redistributions in binary form must reproduce the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer in the
|
10
|
+
# documentation and/or other materials provided with the distribution.
|
11
|
+
# * Neither the name of the Trulia, Inc. nor the
|
12
|
+
# names of its contributors may be used to endorse or promote products
|
13
|
+
# derived from this software without specific prior written permission.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
16
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
17
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
18
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TRULIA, INC. BE
|
19
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
20
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
21
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
22
|
+
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
23
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
24
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
25
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
|
27
|
+
class HologramMarkdownRenderer < Redcarpet::Render::HTML
|
28
|
+
def block_code(code, language)
|
29
|
+
if language and language.include?('example')
|
30
|
+
if language.include?('js')
|
31
|
+
# first actually insert the code in the docs so that it will run and make our example work.
|
32
|
+
'<script>' + code + '</script>
|
33
|
+
<div class="codeBlock jsExample">' + Pygments.highlight(code) + '</div>'
|
34
|
+
else
|
35
|
+
'<div class="codeExample">' + '<div class="exampleOutput">' + code + '</div>' + '<div class="codeBlock">' + Pygments.highlight(code) + '</div>' + '</div>'
|
36
|
+
end
|
37
|
+
else
|
38
|
+
'<div class="codeBlock">' + Pygments.highlight(code) + '</div>'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hologram
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- JD Cantrell
|
8
|
+
- August Flanagan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redcarpet
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.2.2
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.2.2
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sass
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.2.7
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 3.2.7
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pygments.rb
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.4.2
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.4.2
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.3'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.3'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: Build doc type things
|
85
|
+
email:
|
86
|
+
- jcantrell@trulia.com
|
87
|
+
executables:
|
88
|
+
- hologram
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/hologram
|
98
|
+
- hologram.gemspec
|
99
|
+
- lib/hologram.rb
|
100
|
+
- lib/hologram/version.rb
|
101
|
+
- lib/hologram_markdown_renderer.rb
|
102
|
+
homepage: http://trulia.github.io/hologram
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.0.0
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Build document type things.
|
126
|
+
test_files: []
|