hologram 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +61 -0
- data/README.md +33 -5
- data/hologram.gemspec +2 -2
- data/lib/hologram.rb +3 -1
- data/lib/hologram/cli.rb +10 -4
- data/lib/hologram/doc_block_collection.rb +1 -0
- data/lib/hologram/doc_builder.rb +32 -11
- data/lib/hologram/doc_parser.rb +21 -7
- data/lib/hologram/document_block.rb +1 -0
- data/lib/hologram/markdown_renderer.rb +7 -4
- data/lib/hologram/plugin.rb +84 -0
- data/lib/hologram/plugins.rb +49 -0
- data/lib/hologram/utils.rb +7 -2
- data/lib/hologram/version.rb +1 -1
- data/lib/template/doc_assets/_header.html +15 -15
- data/spec/cli_spec.rb +1 -1
- data/spec/display_message_spec.rb +1 -1
- data/spec/doc_builder_spec.rb +78 -19
- data/spec/doc_parser_spec.rb +17 -2
- data/spec/fixtures/source/colors/colors.css +11 -0
- data/spec/fixtures/source/config_multi_source.yml +19 -0
- data/spec/fixtures/styleguide/base_css.html +2 -2
- data/spec/utils_spec.rb +1 -1
- metadata +22 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d23baf9cab5e0651cfa087dd470867770389fb4
|
4
|
+
data.tar.gz: 69b89861f9dbc9a09dc720d9e6a5e1f9ee3b4485
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eeb3b8e627c7f0dbfc5d4b8b73458ea6da97111979cd734e239e7daa34ba1d4304c6accb1488b4404ba23a1c8f581453d420a48b96f99eaa552583fc265fb32
|
7
|
+
data.tar.gz: 84684a77e6dff76831cb74ec9d0cb33ff299b59593c6f4865dc4d0d960217e9a458466980fdf156ed50810b34179339d98845beb274972855574528fa51f4035
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#Changelog
|
2
|
+
|
3
|
+
##1.2.0 - 2014-07-22
|
4
|
+
|
5
|
+
JD Cantrell
|
6
|
+
* Replace pygments with rouge
|
7
|
+
* Add in initial plugin support
|
8
|
+
|
9
|
+
Todd Sedano
|
10
|
+
* Update specs to use `be_truthy` and `be_falsy` (fixes deprecation
|
11
|
+
warnings)
|
12
|
+
|
13
|
+
Carsten Zimmermann
|
14
|
+
* Update redcarpet dependency to use newer versions of redcarpet
|
15
|
+
|
16
|
+
Geoffrey Giesemann, Vanessa de Sant Anna, Nicole Sullivan
|
17
|
+
* Add support for multiple source directories in the hologram config
|
18
|
+
|
19
|
+
rishabhsrao
|
20
|
+
* Remove the --root command line flag
|
21
|
+
|
22
|
+
Marek
|
23
|
+
* Add missing div tag in `_header.html`
|
24
|
+
|
25
|
+
Todd Sedano, bigethan, August Flanagan, JD Cantrell
|
26
|
+
* Many useful readme updates
|
27
|
+
|
28
|
+
##1.1.0 - 2014-05-13
|
29
|
+
|
30
|
+
Rajan Agaskar, Dominick Reinhold, and Nicole Sullivan
|
31
|
+
* Support multiple categories
|
32
|
+
* Create assets when output directory does not exist
|
33
|
+
|
34
|
+
jho406
|
35
|
+
* Major Clean up and refactors
|
36
|
+
* Code climate badge
|
37
|
+
* Readme updates
|
38
|
+
* Spec updates
|
39
|
+
|
40
|
+
|
41
|
+
JD Cantrell
|
42
|
+
* Use UTF-8 as default encoding
|
43
|
+
* Do not error when a directory name matches a supported file type
|
44
|
+
* Sort documentation blocks case insensitively
|
45
|
+
* Support .erb files
|
46
|
+
* Pass in config and full pages object to .erb templates
|
47
|
+
* If title does not exist default it to title with underscores
|
48
|
+
* Display an error when a documentation block does not have a category
|
49
|
+
* Warn when the parent block is specified but could not be found
|
50
|
+
* Add -c flag for specifying config (you may still specify the config as
|
51
|
+
the first parameter to hologram)
|
52
|
+
|
53
|
+
August Flanagan
|
54
|
+
* Remove rspec as a runtime dependency
|
55
|
+
|
56
|
+
James Myers & Madhura Bhave
|
57
|
+
* A rendering scope can now be defined when using haml_examples
|
58
|
+
|
59
|
+
Mike Wilkes
|
60
|
+
* Documentation clean ups
|
61
|
+
* Fix a typo in the config template
|
data/README.md
CHANGED
@@ -40,6 +40,19 @@ This will create a `hologram_config.yml` file (more on this below), and
|
|
40
40
|
also create a starter `_header.html` and `_footer.html` file for you.
|
41
41
|
You can then tweak the config values and start documenting your css.
|
42
42
|
|
43
|
+
Add some documentation to one of your stylesheets:
|
44
|
+
|
45
|
+
/*doc
|
46
|
+
---
|
47
|
+
title: Alert
|
48
|
+
name: alert
|
49
|
+
category: basics
|
50
|
+
---
|
51
|
+
```html_example
|
52
|
+
<div class='alert'>Hello</div>
|
53
|
+
```
|
54
|
+
*/
|
55
|
+
|
43
56
|
Building the documentation is simply:
|
44
57
|
|
45
58
|
``` hologram ```
|
@@ -51,9 +64,6 @@ Hologram has a couple of command line flags:
|
|
51
64
|
|
52
65
|
* `-c` or `--config` - specify the config file, by default hologram
|
53
66
|
looks for `hologram_config.yml`
|
54
|
-
* `-r` or `--root` - specify the directory to use when processing files
|
55
|
-
(useful if you run hologram in a different directory than your assets.
|
56
|
-
Defaults to current working directory)
|
57
67
|
|
58
68
|
## Details
|
59
69
|
|
@@ -75,7 +85,8 @@ hologram path/to/your/config.yml`
|
|
75
85
|
|
76
86
|
Your config file needs to contain the following key/value pairs
|
77
87
|
|
78
|
-
* **source**: relative path to your source files
|
88
|
+
* **source**: relative path(s) to your source files. Accepts either a
|
89
|
+
single value or an array
|
79
90
|
|
80
91
|
* **destination**: relative path where you want the documentation to be
|
81
92
|
built
|
@@ -127,6 +138,11 @@ Your config file needs to contain the following key/value pairs
|
|
127
138
|
# The directory containing the source files to parse recursively
|
128
139
|
source: ./sass
|
129
140
|
|
141
|
+
# You may alternately specify multiple directories.
|
142
|
+
# source:
|
143
|
+
# - ./sass
|
144
|
+
# - ./library-sass
|
145
|
+
|
130
146
|
# The directory that hologram will build to
|
131
147
|
destination: ./docs
|
132
148
|
|
@@ -172,6 +188,8 @@ in your configuration. It will look for comments that match the following:
|
|
172
188
|
|
173
189
|
*/
|
174
190
|
|
191
|
+
**NB:** Sass users who are using the `.sass` flavor of Sass should use `//doc` style comments with indents to create their comment blocks.
|
192
|
+
|
175
193
|
The first section of the comment is a YAML block that defines certain
|
176
194
|
aspects of this documentation block (more on that in the next
|
177
195
|
section). The second part is simply markdown as defined by Redcarpet.
|
@@ -256,7 +274,13 @@ The following preprocessors/file types are supported by Hologram:
|
|
256
274
|
- [Guard Hologram](https://github.com/kmayer/guard-hologram) is a sweet
|
257
275
|
little gem that uses guard to monitor changes to your hologram project
|
258
276
|
and rebuilds your style guide on the fly as you make changes.
|
259
|
-
|
277
|
+
- [Grunt Hologram](https://github.com/jchild3rs/grunt-hologram/) is a sweet
|
278
|
+
little grunt task that will generate your hologram style guide.
|
279
|
+
- [Classname Clicker](https://github.com/bigethan/hologram-addons/) is a handy
|
280
|
+
UI addition that gives the ability to see rules that apply to a classname by
|
281
|
+
clicking on them within hologram.
|
282
|
+
- [Cortana](https://github.com/Yago/Cortana) is a theme for hologram. It also
|
283
|
+
includes a handy search feature.
|
260
284
|
|
261
285
|
## Contributing
|
262
286
|
|
@@ -285,7 +309,11 @@ These fine people have also contributed to making hologram a better gem:
|
|
285
309
|
* [Elana Koren](https://github.com/elanakoren)
|
286
310
|
* [Ken Mayer](https://github.com/kmayer)
|
287
311
|
* [Roberto Ostinelli](https://github.com/ostinelli)
|
312
|
+
* [Dominick Reinhold](https://github.com/d-reinhold)
|
288
313
|
* [Nicole Sullivan](https://github.com/stubbornella)
|
314
|
+
* [Mike Wilkes](https://github.com/mikezx6r)
|
315
|
+
* [Vanessa Sant'Anna](https://github.com/vsanta)
|
316
|
+
* [Geoffrey Giesemann](https://github.com/geoffwa)
|
289
317
|
|
290
318
|
|
291
319
|
## License
|
data/hologram.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "http://trulia.github.io/hologram"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.add_dependency "redcarpet", "
|
17
|
-
spec.add_dependency "
|
16
|
+
spec.add_dependency "redcarpet", ">= 2.2", "< 4.0"
|
17
|
+
spec.add_dependency "rouge", ">= 1.5"
|
18
18
|
|
19
19
|
spec.files = `git ls-files`.split($/)
|
20
20
|
spec.executables = ['hologram']
|
data/lib/hologram.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'redcarpet'
|
2
2
|
require 'yaml'
|
3
|
-
require '
|
3
|
+
require 'rouge'
|
4
4
|
require 'fileutils'
|
5
5
|
require 'pathname'
|
6
6
|
require 'erb'
|
7
7
|
|
8
8
|
require 'hologram/version'
|
9
|
+
require 'hologram/plugin'
|
10
|
+
require 'hologram/plugins'
|
9
11
|
require 'hologram/document_block'
|
10
12
|
require 'hologram/doc_block_collection'
|
11
13
|
require 'hologram/doc_parser'
|
data/lib/hologram/cli.rb
CHANGED
@@ -10,6 +10,7 @@ module Hologram
|
|
10
10
|
|
11
11
|
def run
|
12
12
|
return setup if args[0] == 'init'
|
13
|
+
extra_args = []
|
13
14
|
|
14
15
|
#support passing the config file with no command line flag
|
15
16
|
config = args[0].nil? ? 'hologram_config.yml' : args[0]
|
@@ -18,16 +19,21 @@ module Hologram
|
|
18
19
|
opt.on_tail('-h', '--help', 'Show this message.') { puts opt; exit }
|
19
20
|
opt.on_tail('-v', '--version', 'Show version.') { puts "hologram #{Hologram::VERSION}"; exit }
|
20
21
|
opt.on('-c', '--config FILE', 'Path to config file. Default: hologram_config.yml') { |config_file| config = config_file }
|
21
|
-
|
22
|
+
begin
|
23
|
+
opt.parse!(args)
|
24
|
+
rescue OptionParser::InvalidOption => e
|
25
|
+
extra_args.push(e.to_s.sub(/invalid option:\s+/, ''))
|
26
|
+
end
|
27
|
+
|
22
28
|
end
|
23
29
|
|
24
|
-
config.nil? ? build : build(config)
|
30
|
+
config.nil? ? build(extra_args) : build(extra_args, config)
|
25
31
|
|
26
32
|
end
|
27
33
|
|
28
34
|
private
|
29
|
-
def build(config = 'hologram_config.yml')
|
30
|
-
builder = DocBuilder.from_yaml(config)
|
35
|
+
def build(extra_args = [], config = 'hologram_config.yml')
|
36
|
+
builder = DocBuilder.from_yaml(config, extra_args)
|
31
37
|
DisplayMessage.error(builder.errors.first) if !builder.is_valid?
|
32
38
|
builder.build
|
33
39
|
rescue CommentLoadError, NoCategoryError => e
|
data/lib/hologram/doc_builder.rb
CHANGED
@@ -4,7 +4,7 @@ module Hologram
|
|
4
4
|
attr_reader :errors
|
5
5
|
attr :doc_assets_dir, :output_dir, :input_dir, :header_erb, :footer_erb
|
6
6
|
|
7
|
-
def self.from_yaml(yaml_file)
|
7
|
+
def self.from_yaml(yaml_file, extra_args = [])
|
8
8
|
|
9
9
|
#Change dir so that our paths are relative to the config file
|
10
10
|
base_path = Pathname.new(yaml_file)
|
@@ -18,7 +18,7 @@ module Hologram
|
|
18
18
|
'config_yml' => config,
|
19
19
|
'base_path' => Pathname.new(yaml_file).dirname,
|
20
20
|
'renderer' => Utils.get_markdown_renderer(config['custom_markdown'])
|
21
|
-
))
|
21
|
+
), extra_args)
|
22
22
|
|
23
23
|
rescue SyntaxError, ArgumentError, Psych::SyntaxError
|
24
24
|
raise SyntaxError, "Could not load config file, check the syntax or try 'hologram init' to get started"
|
@@ -35,17 +35,18 @@ module Hologram
|
|
35
35
|
DisplayMessage.created(new_files)
|
36
36
|
end
|
37
37
|
|
38
|
-
def initialize(options)
|
38
|
+
def initialize(options, extra_args = [])
|
39
39
|
@pages = {}
|
40
40
|
@errors = []
|
41
|
-
@dependencies = options.fetch('dependencies', []
|
41
|
+
@dependencies = options.fetch('dependencies', nil) || []
|
42
42
|
@index = options['index']
|
43
43
|
@base_path = options.fetch('base_path', Dir.pwd)
|
44
44
|
@renderer = options.fetch('renderer', MarkdownRenderer)
|
45
|
-
@source = options['source']
|
45
|
+
@source = Array(options['source'])
|
46
46
|
@destination = options['destination']
|
47
47
|
@documentation_assets = options['documentation_assets']
|
48
48
|
@config_yml = options['config_yml']
|
49
|
+
@plugins = Plugins.new(options.fetch('config_yml', {}), extra_args)
|
49
50
|
end
|
50
51
|
|
51
52
|
def build
|
@@ -70,19 +71,35 @@ module Hologram
|
|
70
71
|
def is_valid?
|
71
72
|
errors.clear
|
72
73
|
set_dirs
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
validate_source
|
75
|
+
validate_destination
|
76
|
+
validate_document_assets
|
77
|
+
|
77
78
|
errors.empty?
|
78
79
|
end
|
79
80
|
|
80
81
|
private
|
81
82
|
|
83
|
+
def validate_source
|
84
|
+
errors << "No source directory specified in the config file" if source.empty?
|
85
|
+
source.each do |dir|
|
86
|
+
next if real_path(dir)
|
87
|
+
errors << "Can not read source directory (#{dir}), does it exist?"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def validate_destination
|
92
|
+
errors << "No destination directory specified in the config" if !destination
|
93
|
+
end
|
94
|
+
|
95
|
+
def validate_document_assets
|
96
|
+
errors << "No documentation assets directory specified" if !documentation_assets
|
97
|
+
end
|
98
|
+
|
82
99
|
def set_dirs
|
83
100
|
@output_dir = real_path(destination)
|
84
101
|
@doc_assets_dir = real_path(documentation_assets)
|
85
|
-
@input_dir =
|
102
|
+
@input_dir = multiple_paths(source)
|
86
103
|
end
|
87
104
|
|
88
105
|
def real_path(dir)
|
@@ -90,8 +107,12 @@ module Hologram
|
|
90
107
|
Pathname.new(dir).realpath
|
91
108
|
end
|
92
109
|
|
110
|
+
def multiple_paths dirs
|
111
|
+
Array(dirs).map { |dir| real_path(dir) }.compact
|
112
|
+
end
|
113
|
+
|
93
114
|
def build_docs
|
94
|
-
doc_parser = DocParser.new(input_dir, index)
|
115
|
+
doc_parser = DocParser.new(input_dir, index, @plugins)
|
95
116
|
@pages, @categories = doc_parser.parse
|
96
117
|
|
97
118
|
if index && !@pages.has_key?(index + '.html')
|
data/lib/hologram/doc_parser.rb
CHANGED
@@ -3,8 +3,9 @@ module Hologram
|
|
3
3
|
SUPPORTED_EXTENSIONS = ['.css', '.scss', '.less', '.sass', '.styl', '.js', '.md', '.markdown', '.erb' ]
|
4
4
|
attr_accessor :source_path, :pages, :doc_blocks
|
5
5
|
|
6
|
-
def initialize(source_path, index_name = nil)
|
7
|
-
@
|
6
|
+
def initialize(source_path, index_name = nil, plugins)
|
7
|
+
@plugins = plugins
|
8
|
+
@source_paths = Array(source_path)
|
8
9
|
@index_name = index_name
|
9
10
|
@pages = {}
|
10
11
|
@output_files_by_category = {}
|
@@ -16,7 +17,12 @@ module Hologram
|
|
16
17
|
# comments matching the hologram doc style /*doc */ and create DocBlock
|
17
18
|
# objects from those comments, then add those to a collection object which
|
18
19
|
# is then returned.
|
19
|
-
|
20
|
+
|
21
|
+
doc_block_collection = DocBlockCollection.new
|
22
|
+
|
23
|
+
@source_paths.each do |source_path|
|
24
|
+
process_dir(source_path, doc_block_collection)
|
25
|
+
end
|
20
26
|
|
21
27
|
# doc blocks can define parent/child relationships that will nest their
|
22
28
|
# documentation appropriately. we can't put everything into that structure
|
@@ -29,6 +35,8 @@ module Hologram
|
|
29
35
|
# hand off our properly nested collection to the output generator
|
30
36
|
build_output(doc_block_collection.doc_blocks)
|
31
37
|
|
38
|
+
@plugins.finalize(@pages)
|
39
|
+
|
32
40
|
# if we have an index category defined in our config copy that
|
33
41
|
# page to index.html
|
34
42
|
if @index_name
|
@@ -43,9 +51,8 @@ module Hologram
|
|
43
51
|
|
44
52
|
private
|
45
53
|
|
46
|
-
def process_dir(base_directory)
|
54
|
+
def process_dir(base_directory, doc_block_collection)
|
47
55
|
#get all directories in our library folder
|
48
|
-
doc_block_collection = DocBlockCollection.new
|
49
56
|
directories = Dir.glob("#{base_directory}/**/*/")
|
50
57
|
directories.unshift(base_directory)
|
51
58
|
|
@@ -58,7 +65,6 @@ module Hologram
|
|
58
65
|
files.sort!
|
59
66
|
process_files(files, directory, doc_block_collection)
|
60
67
|
end
|
61
|
-
doc_block_collection
|
62
68
|
end
|
63
69
|
|
64
70
|
def process_files(files, directory, doc_block_collection)
|
@@ -85,8 +91,15 @@ module Hologram
|
|
85
91
|
end
|
86
92
|
return unless hologram_comments
|
87
93
|
|
94
|
+
|
95
|
+
|
88
96
|
hologram_comments.each do |comment_block|
|
89
|
-
doc_block_collection.add_doc_block(comment_block[0], file)
|
97
|
+
block = doc_block_collection.add_doc_block(comment_block[0], file)
|
98
|
+
|
99
|
+
if (!block.nil?)
|
100
|
+
@plugins.block(block, file)
|
101
|
+
end
|
102
|
+
|
90
103
|
end
|
91
104
|
end
|
92
105
|
|
@@ -104,6 +117,7 @@ module Hologram
|
|
104
117
|
end
|
105
118
|
build_output(doc_block.children, nil, depth + 1)
|
106
119
|
end
|
120
|
+
|
107
121
|
end
|
108
122
|
|
109
123
|
def is_supported_file_type?(file)
|
@@ -1,16 +1,19 @@
|
|
1
1
|
module Hologram
|
2
2
|
class MarkdownRenderer < Redcarpet::Render::HTML
|
3
3
|
def block_code(code, language)
|
4
|
+
formatter = Rouge::Formatters::HTML.new(wrap: false)
|
4
5
|
if language and language.include?('example')
|
5
6
|
if language.include?('js')
|
7
|
+
lexer = Rouge::Lexer.find('js')
|
6
8
|
# first actually insert the code in the docs so that it will run and make our example work.
|
7
|
-
'<script>' + code + '</script>
|
8
|
-
<div class="codeBlock jsExample">' + Pygments.highlight(code) + '</div>'
|
9
|
+
'<script>' + code + '</script> <div class="codeBlock jsExample"><div class="highlight"><pre>' + formatter.format(lexer.lex(code)) + '</pre></div></div>'
|
9
10
|
else
|
10
|
-
|
11
|
+
lexer = Rouge::Lexer.find(get_lexer(language))
|
12
|
+
'<div class="codeExample">' + '<div class="exampleOutput">' + render_html(code, language) + '</div>' + '<div class="codeBlock"><div class="highlight"><pre>' + formatter.format(lexer.lex(code)) + '</pre></div></div>' + '</div>'
|
11
13
|
end
|
12
14
|
else
|
13
|
-
|
15
|
+
lexer = Rouge::Lexer.find_fancy('guess', code)
|
16
|
+
'<div class="codeBlock"><div class="highlight"><pre>' + formatter.format(lexer.lex(code)) + '</pre></div></div>'
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Hologram
|
2
|
+
class Plugin
|
3
|
+
attr :active, :name
|
4
|
+
|
5
|
+
# Plugin constructor:
|
6
|
+
# +config+: This is the config object generated from the config file
|
7
|
+
# hologram was loaded with
|
8
|
+
# +args+: These are the command line arguments hologram was run with
|
9
|
+
def initialize(config, args)
|
10
|
+
@active = self.get_active(args);
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_active(args)
|
14
|
+
flagged = false
|
15
|
+
OptionParser.new do |opt|
|
16
|
+
opt.on_tail("--#{@name}") { flagged = true }
|
17
|
+
begin
|
18
|
+
opt.parse!(args)
|
19
|
+
rescue OptionParser::InvalidOption
|
20
|
+
flagged = false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
return flagged
|
25
|
+
end
|
26
|
+
|
27
|
+
def is_active?()
|
28
|
+
@active
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_block(comment_block, file)
|
32
|
+
|
33
|
+
plugin_sections = comment_block.markdown.scan(/^\s*\[\[\[plugin:#{Regexp.quote(@name)}(.*?)\]\]\]/m)
|
34
|
+
|
35
|
+
if self.is_active?
|
36
|
+
|
37
|
+
self.block(comment_block, file, !plugin_sections.empty?)
|
38
|
+
|
39
|
+
for section in plugin_sections
|
40
|
+
plugin_data = section[0]
|
41
|
+
replace_text = self.plugin(plugin_data, comment_block, file)
|
42
|
+
comment_block.markdown = comment_block.markdown.gsub("[[[plugin:#{@name}#{plugin_data}]]]", replace_text)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
# plugin is inactive, so remove it from our markdown
|
46
|
+
for section in plugin_sections
|
47
|
+
plugin_data = section[0]
|
48
|
+
comment_block.markdown = comment_block.markdown.gsub("[[[plugin:#{@name}#{plugin_data}]]]", '')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
# This is called on every block that hologram parses.
|
55
|
+
# Params:
|
56
|
+
# +comment_block+: This is a doc_block object. It provides name,
|
57
|
+
# children, title, markdown, yml config accessors.
|
58
|
+
# +filename+: The filename for the current file being processed
|
59
|
+
# +has_plugin+: This is a boolean that is true if this comment block
|
60
|
+
# has plugin data for this plugin and false otherwise.
|
61
|
+
def block(comment_block, filename, has_plugin) end
|
62
|
+
|
63
|
+
# This is called everytime parse_block encounters a [[[plugin:name ]]]
|
64
|
+
# section.
|
65
|
+
# Params:
|
66
|
+
# +data+: The text inside the plugin section.
|
67
|
+
# +block+: The current doc_block object
|
68
|
+
# +filename+: The filename of the file the plugin section is in
|
69
|
+
#
|
70
|
+
# Returns: A string that will replace the plugin block in the
|
71
|
+
# documentation
|
72
|
+
def plugin(data, block, filename)
|
73
|
+
return ""
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# This method is called after hologram has processed all the source
|
78
|
+
# files. Pages is a dictionary of html pages to be written. The key is
|
79
|
+
# the file name while the value is the html source.
|
80
|
+
def finalize(pages) end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Hologram
|
2
|
+
class Plugins
|
3
|
+
|
4
|
+
attr_accessor :plugins
|
5
|
+
|
6
|
+
def initialize(config = {}, args)
|
7
|
+
@plugins = []
|
8
|
+
|
9
|
+
if config.has_key?('plugins')
|
10
|
+
for plugin_file in config['plugins']
|
11
|
+
plugin_path = Pathname.new(plugin_file).realpath
|
12
|
+
load plugin_path
|
13
|
+
plugin_class = Utils.get_class_name(plugin_file)
|
14
|
+
register(plugin_class, config, args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def register(plugin_class, config, args)
|
20
|
+
clazz = Object.const_get(plugin_class)
|
21
|
+
obj = clazz.new(config, args)
|
22
|
+
if obj.is_active?
|
23
|
+
DisplayMessage.info("Plugin active: #{plugin_class}")
|
24
|
+
else
|
25
|
+
DisplayMessage.info("Plugin not active: #{plugin_class}")
|
26
|
+
end
|
27
|
+
|
28
|
+
@plugins.push(obj)
|
29
|
+
end
|
30
|
+
|
31
|
+
def block(comment_block, file)
|
32
|
+
for plugin in @plugins
|
33
|
+
#We parse comment blocks even when the plugin is not active,
|
34
|
+
#this allows us to remove the plugin's data blocks from the
|
35
|
+
#markdown output
|
36
|
+
plugin.parse_block(comment_block, file)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def finalize(pages)
|
41
|
+
for plugin in @plugins
|
42
|
+
if plugin.is_active?
|
43
|
+
plugin.finalize(pages)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/lib/hologram/utils.rb
CHANGED
@@ -3,8 +3,9 @@ module Hologram
|
|
3
3
|
def self.get_markdown_renderer(custom_markdown = nil)
|
4
4
|
return MarkdownRenderer if custom_markdown.nil?
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
md_file = Pathname.new(custom_markdown).realpath
|
7
|
+
load md_file
|
8
|
+
renderer_class = self.get_class_name(custom_markdown)
|
8
9
|
DisplayMessage.info("Custom markdown renderer #{renderer_class} loaded.")
|
9
10
|
Module.const_get(renderer_class)
|
10
11
|
rescue LoadError => e
|
@@ -12,5 +13,9 @@ module Hologram
|
|
12
13
|
rescue NameError => e
|
13
14
|
DisplayMessage.error("Class #{renderer_class} not found in #{custom_markdown}.")
|
14
15
|
end
|
16
|
+
|
17
|
+
def self.get_class_name(file)
|
18
|
+
File.basename(file, '.rb').split(/_/).map(&:capitalize).join
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
data/lib/hologram/version.rb
CHANGED
@@ -5,19 +5,19 @@
|
|
5
5
|
<link rel="stylesheet" href="./your_stylesheet_here.css">
|
6
6
|
</head>
|
7
7
|
<body>
|
8
|
+
<div>
|
9
|
+
<nav>
|
10
|
+
<ul>
|
11
|
+
<% @categories.each do |category, file_name| %>
|
12
|
+
<li><a href="<%= file_name %>"><%= category %></a></li>
|
13
|
+
<% end %>
|
14
|
+
</ul>
|
15
|
+
</nav>
|
8
16
|
|
9
|
-
|
10
|
-
<
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
<h1>a brand new style guide, it's super effective</h1>
|
18
|
-
<section class="content">
|
19
|
-
<ul>
|
20
|
-
<% @blocks.each do |b| %>
|
21
|
-
<li><a href="#<%= b[:name] %>"><%= b[:title] %></a></li>
|
22
|
-
<% end %>
|
23
|
-
</ul>
|
17
|
+
<h1>a brand new style guide, it's super effective</h1>
|
18
|
+
<section class="content">
|
19
|
+
<ul>
|
20
|
+
<% @blocks.each do |b| %>
|
21
|
+
<li><a href="#<%= b[:name] %>"><%= b[:title] %></a></li>
|
22
|
+
<% end %>
|
23
|
+
</ul>
|
data/spec/cli_spec.rb
CHANGED
@@ -29,7 +29,7 @@ describe Hologram::CLI do
|
|
29
29
|
subject(:builder) { double(Hologram::DocBuilder, is_valid?: true, build: true) }
|
30
30
|
|
31
31
|
it 'builds the documentation' do
|
32
|
-
expect(Hologram::DocBuilder).to receive(:from_yaml).with('test.yml').and_return(builder)
|
32
|
+
expect(Hologram::DocBuilder).to receive(:from_yaml).with('test.yml', []).and_return(builder)
|
33
33
|
cli.run
|
34
34
|
end
|
35
35
|
end
|
data/spec/doc_builder_spec.rb
CHANGED
@@ -11,24 +11,34 @@ describe Hologram::DocBuilder do
|
|
11
11
|
|
12
12
|
context '.from_yaml' do
|
13
13
|
subject(:builder) { Hologram::DocBuilder }
|
14
|
+
let(:spec_root) { File.expand_path('../', __FILE__) }
|
15
|
+
let(:tmpdir) { @tmpdir }
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
around do |example|
|
20
|
-
Dir.mktmpdir do |tmpdir|
|
21
|
-
FileUtils.cp(config_path, config_copy_path)
|
22
|
-
File.open(config_copy_path, 'a'){ |io| io << "destination: #{tmpdir}" }
|
23
|
-
current_dir = Dir.pwd
|
24
|
-
Dir.chdir(tmpdir)
|
17
|
+
around do |example|
|
18
|
+
Dir.mktmpdir do |tmpdir|
|
19
|
+
@tmpdir = tmpdir
|
20
|
+
current_dir = Dir.pwd
|
25
21
|
|
22
|
+
begin
|
23
|
+
Dir.chdir(tmpdir)
|
26
24
|
example.run
|
27
|
-
|
25
|
+
ensure
|
28
26
|
Dir.chdir(current_dir)
|
29
|
-
FileUtils.rm(config_copy_path)
|
30
27
|
end
|
31
28
|
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when passed a valid config file' do
|
32
|
+
let(:config_path) { File.join(spec_root, 'fixtures/source/config.yml') }
|
33
|
+
let(:config_copy_path) { File.join(spec_root, 'fixtures/source/config.yml.copy') }
|
34
|
+
|
35
|
+
before do
|
36
|
+
FileUtils.cp(config_path, config_copy_path)
|
37
|
+
File.open(config_copy_path, 'a'){ |io| io << "destination: #{tmpdir}" }
|
38
|
+
end
|
39
|
+
after do
|
40
|
+
FileUtils.rm(config_copy_path)
|
41
|
+
end
|
32
42
|
|
33
43
|
it 'returns a DocBuilder instance' do
|
34
44
|
expect(subject.from_yaml(config_copy_path)).to be_a Hologram::DocBuilder
|
@@ -48,6 +58,41 @@ describe Hologram::DocBuilder do
|
|
48
58
|
expect { subject.from_yaml('bad_config.yml') }.to raise_error SyntaxError
|
49
59
|
end
|
50
60
|
end
|
61
|
+
|
62
|
+
context 'when source option is an array' do
|
63
|
+
let(:config_path) { File.join(spec_root, 'fixtures/source/config_multi_source.yml') }
|
64
|
+
let(:config_copy_path) { File.join(spec_root, 'fixtures/source/config_multi_source.yml.copy') }
|
65
|
+
|
66
|
+
before do
|
67
|
+
FileUtils.cp(config_path, config_copy_path)
|
68
|
+
File.open(config_copy_path, 'a'){ |io| io << "destination: #{tmpdir}" }
|
69
|
+
end
|
70
|
+
after do
|
71
|
+
FileUtils.rm(config_copy_path)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns a DocBuilder instance' do
|
75
|
+
expect(subject.from_yaml(config_copy_path)).to be_a Hologram::DocBuilder
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when dependencies is left blank' do
|
80
|
+
let(:yaml) { "dependencies:\n" }
|
81
|
+
|
82
|
+
before do
|
83
|
+
File.open('fixable_bad_config.yml', 'w'){ |io| io << yaml }
|
84
|
+
end
|
85
|
+
|
86
|
+
after do
|
87
|
+
FileUtils.rm('fixable_bad_config.yml')
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'deletes the empty config variable' do
|
91
|
+
builder = subject.from_yaml('fixable_bad_config.yml')
|
92
|
+
expect(builder).to be_a Hologram::DocBuilder
|
93
|
+
expect(builder.dependencies).to eql []
|
94
|
+
end
|
95
|
+
end
|
51
96
|
end
|
52
97
|
|
53
98
|
context '.setup_dir' do
|
@@ -66,13 +111,13 @@ describe Hologram::DocBuilder do
|
|
66
111
|
end
|
67
112
|
|
68
113
|
it 'creates a config file' do
|
69
|
-
expect(File.exists?('hologram_config.yml')).to
|
114
|
+
expect(File.exists?('hologram_config.yml')).to be_truthy
|
70
115
|
end
|
71
116
|
|
72
117
|
it 'creates default assets' do
|
73
118
|
Dir.chdir('doc_assets') do
|
74
119
|
['_header.html', '_footer.html'].each do |asset|
|
75
|
-
expect(File.exists?(asset)).to
|
120
|
+
expect(File.exists?(asset)).to be_truthy
|
76
121
|
end
|
77
122
|
end
|
78
123
|
end
|
@@ -107,7 +152,7 @@ describe Hologram::DocBuilder do
|
|
107
152
|
|
108
153
|
context 'when config vars are present and directories exists' do
|
109
154
|
it 'returns true' do
|
110
|
-
expect(builder.is_valid?).to
|
155
|
+
expect(builder.is_valid?).to be_truthy
|
111
156
|
end
|
112
157
|
end
|
113
158
|
|
@@ -118,7 +163,7 @@ describe Hologram::DocBuilder do
|
|
118
163
|
end
|
119
164
|
|
120
165
|
it 'returns false' do
|
121
|
-
expect(builder.is_valid?).to
|
166
|
+
expect(builder.is_valid?).to be_falsy
|
122
167
|
end
|
123
168
|
|
124
169
|
it 'populates errors' do
|
@@ -128,13 +173,13 @@ describe Hologram::DocBuilder do
|
|
128
173
|
end
|
129
174
|
end
|
130
175
|
|
131
|
-
context
|
176
|
+
context 'when the source directory does not exist' do
|
132
177
|
before do
|
133
178
|
config['source'] = './foo'
|
134
179
|
end
|
135
180
|
|
136
181
|
it 'returns false' do
|
137
|
-
expect(builder.is_valid?).to
|
182
|
+
expect(builder.is_valid?).to be_falsy
|
138
183
|
end
|
139
184
|
|
140
185
|
it 'populates errors' do
|
@@ -142,6 +187,20 @@ describe Hologram::DocBuilder do
|
|
142
187
|
expect(builder.errors.size).to eql 1
|
143
188
|
end
|
144
189
|
end
|
190
|
+
|
191
|
+
context 'when source is an array' do
|
192
|
+
let(:config) do
|
193
|
+
{
|
194
|
+
'source' => ['spec/fixtures/source/components', 'spec/fixtures/source/templates'],
|
195
|
+
'documentation_assets' => 'spec/fixtures/source/templates',
|
196
|
+
'base_path' => 'spec/fixtures/source/'
|
197
|
+
}
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'returns true' do
|
201
|
+
expect(builder.is_valid?).to be_truthy
|
202
|
+
end
|
203
|
+
end
|
145
204
|
end
|
146
205
|
|
147
206
|
context '#build' do
|
@@ -168,7 +227,7 @@ describe Hologram::DocBuilder do
|
|
168
227
|
it 'builds a styleguide' do
|
169
228
|
builder.build
|
170
229
|
style_files.each_with_index do |file, index|
|
171
|
-
expect(FileUtils.cmp(file, processed_files[index])).to
|
230
|
+
expect(FileUtils.cmp(file, processed_files[index])).to be_truthy
|
172
231
|
end
|
173
232
|
end
|
174
233
|
end
|
data/spec/doc_parser_spec.rb
CHANGED
@@ -58,8 +58,14 @@ multi-parent
|
|
58
58
|
|
59
59
|
let(:source_path) { 'spec/fixtures/source' }
|
60
60
|
let(:temp_doc) { File.join(source_path, 'components', 'button', 'skin', 'testSkin.css') }
|
61
|
+
let(:plugins) {
|
62
|
+
plugins = double()
|
63
|
+
allow(plugins).to receive(:block)
|
64
|
+
allow(plugins).to receive(:finalize)
|
65
|
+
return plugins
|
66
|
+
}
|
61
67
|
|
62
|
-
subject(:parser) { Hologram::DocParser.new('spec/fixtures/source') }
|
68
|
+
subject(:parser) { Hologram::DocParser.new('spec/fixtures/source/components', nil, plugins) }
|
63
69
|
|
64
70
|
context '#parse' do
|
65
71
|
let(:result) { parser.parse }
|
@@ -71,6 +77,15 @@ multi-parent
|
|
71
77
|
expect(output_files_by_category).to be_a Hash
|
72
78
|
end
|
73
79
|
|
80
|
+
context "when the source has multiple paths" do
|
81
|
+
subject(:parser) { Hologram::DocParser.new(['spec/fixtures/source/colors', 'spec/fixtures/source/components'], nil, plugins) }
|
82
|
+
|
83
|
+
it "parses all sources" do
|
84
|
+
expect(pages['base_css.html'][:md]).to include 'Base colors'
|
85
|
+
expect(pages['base_css.html'][:md]).to include 'Background Colors'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
74
89
|
context 'when the component has two categories' do
|
75
90
|
around do |example|
|
76
91
|
File.open(temp_doc, 'a+'){ |io| io << multi_category_doc }
|
@@ -85,7 +100,7 @@ multi-parent
|
|
85
100
|
|
86
101
|
|
87
102
|
context 'when an index page is specified' do
|
88
|
-
subject(:parser) { Hologram::DocParser.new('spec/fixtures/source', 'foo') }
|
103
|
+
subject(:parser) { Hologram::DocParser.new('spec/fixtures/source', 'foo', plugins) }
|
89
104
|
|
90
105
|
around do |example|
|
91
106
|
File.open(temp_doc, 'a+'){ |io| io << doc }
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Hologram config
|
2
|
+
|
3
|
+
# The directory containing the source files to parse
|
4
|
+
source:
|
5
|
+
- ./components
|
6
|
+
- ./templates
|
7
|
+
|
8
|
+
# The assets needed to build the docs (includes header.html, footer.html, etc)
|
9
|
+
documentation_assets: ./templates
|
10
|
+
|
11
|
+
# This is a custom markdown renderer (see Redcarpet documentation for
|
12
|
+
# how to do this)
|
13
|
+
# custom_markdown: trulia_markdown_renderer.rb
|
14
|
+
|
15
|
+
# Any other asset folders that need to be copied to the destination folder
|
16
|
+
# This where you should include your full stylesheets, component javascript,
|
17
|
+
# libraries and any other dependencies your style guide will have
|
18
|
+
dependencies:
|
19
|
+
- ./extra
|
@@ -90,8 +90,8 @@ specific components and modules on the page.</p>
|
|
90
90
|
use either a <code><button></code> or an <code><a></code> element:</p>
|
91
91
|
<div class="codeExample"><div class="exampleOutput"><button class="btn btnDefault">Click</button>
|
92
92
|
<a class="btn btnDefault" href="http://trulia.com">Don't click</a>
|
93
|
-
</div><div class="codeBlock"><div class="highlight"><pre><span class="nt"><button</span> <span class="na">class=</span><span class="s"
|
94
|
-
<span class="nt"><a</span> <span class="na">class=</span><span class="s"
|
93
|
+
</div><div class="codeBlock"><div class="highlight"><pre><span class="nt"><button</span> <span class="na">class=</span><span class="s">"btn btnDefault"</span><span class="nt">></span>Click<span class="nt"></button></span>
|
94
|
+
<span class="nt"><a</span> <span class="na">class=</span><span class="s">"btn btnDefault"</span> <span class="na">href=</span><span class="s">"http://trulia.com"</span><span class="nt">></span>Don't click<span class="nt"></a></span>
|
95
95
|
</pre></div></div></div>
|
96
96
|
<p>If your button is actually a link to another page, please use the
|
97
97
|
<code><a></code> element, while if your button performs an action, such as submitting
|
data/spec/utils_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hologram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JD Cantrell
|
@@ -9,36 +9,42 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redcarpet
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '2.2'
|
21
|
+
- - <
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '4.0'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
|
-
- -
|
28
|
+
- - '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '2.2'
|
31
|
+
- - <
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
35
|
+
name: rouge
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
31
37
|
requirements:
|
32
|
-
- -
|
38
|
+
- - '>='
|
33
39
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
40
|
+
version: '1.5'
|
35
41
|
type: :runtime
|
36
42
|
prerelease: false
|
37
43
|
version_requirements: !ruby/object:Gem::Requirement
|
38
44
|
requirements:
|
39
|
-
- -
|
45
|
+
- - '>='
|
40
46
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
47
|
+
version: '1.5'
|
42
48
|
- !ruby/object:Gem::Dependency
|
43
49
|
name: bundler
|
44
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,6 +97,7 @@ extra_rdoc_files: []
|
|
91
97
|
files:
|
92
98
|
- .gitignore
|
93
99
|
- .travis.yml
|
100
|
+
- CHANGELOG.md
|
94
101
|
- Gemfile
|
95
102
|
- LICENSE.txt
|
96
103
|
- README.md
|
@@ -107,6 +114,8 @@ files:
|
|
107
114
|
- lib/hologram/document_block.rb
|
108
115
|
- lib/hologram/errors.rb
|
109
116
|
- lib/hologram/markdown_renderer.rb
|
117
|
+
- lib/hologram/plugin.rb
|
118
|
+
- lib/hologram/plugins.rb
|
110
119
|
- lib/hologram/template_variables.rb
|
111
120
|
- lib/hologram/utils.rb
|
112
121
|
- lib/hologram/version.rb
|
@@ -121,11 +130,13 @@ files:
|
|
121
130
|
- spec/document_block_spec.rb
|
122
131
|
- spec/fixtures/renderer/invalid_renderer.rb
|
123
132
|
- spec/fixtures/renderer/valid_renderer.rb
|
133
|
+
- spec/fixtures/source/colors/colors.css
|
124
134
|
- spec/fixtures/source/components/background/backgrounds.css
|
125
135
|
- spec/fixtures/source/components/button/buttons.css
|
126
136
|
- spec/fixtures/source/components/button/skin/buttonSkins.css
|
127
137
|
- spec/fixtures/source/components/index.md
|
128
138
|
- spec/fixtures/source/config.yml
|
139
|
+
- spec/fixtures/source/config_multi_source.yml
|
129
140
|
- spec/fixtures/source/extra/css/screen.css
|
130
141
|
- spec/fixtures/source/templates/_footer.html
|
131
142
|
- spec/fixtures/source/templates/_header.html
|
@@ -170,11 +181,13 @@ test_files:
|
|
170
181
|
- spec/document_block_spec.rb
|
171
182
|
- spec/fixtures/renderer/invalid_renderer.rb
|
172
183
|
- spec/fixtures/renderer/valid_renderer.rb
|
184
|
+
- spec/fixtures/source/colors/colors.css
|
173
185
|
- spec/fixtures/source/components/background/backgrounds.css
|
174
186
|
- spec/fixtures/source/components/button/buttons.css
|
175
187
|
- spec/fixtures/source/components/button/skin/buttonSkins.css
|
176
188
|
- spec/fixtures/source/components/index.md
|
177
189
|
- spec/fixtures/source/config.yml
|
190
|
+
- spec/fixtures/source/config_multi_source.yml
|
178
191
|
- spec/fixtures/source/extra/css/screen.css
|
179
192
|
- spec/fixtures/source/templates/_footer.html
|
180
193
|
- spec/fixtures/source/templates/_header.html
|