roger_style_guide 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +47 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +80 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +16 -0
- data/lib/roger_style_guide/generators/component/template/%component_name%.html.erb.tt +5 -0
- data/lib/roger_style_guide/generators/component/template/%component_name%.js +0 -0
- data/lib/roger_style_guide/generators/component/template/_%component_name%.%partial_extension% +0 -0
- data/lib/roger_style_guide/generators/component/template/_%component_name%.scss +0 -0
- data/lib/roger_style_guide/generators/component_generator.rb +56 -0
- data/lib/roger_style_guide/generators.rb +5 -0
- data/lib/roger_style_guide/helpers/component_helper.rb +43 -0
- data/lib/roger_style_guide/helpers/toc_helper.rb +145 -0
- data/lib/roger_style_guide/helpers.rb +6 -0
- data/lib/roger_style_guide/templates/mustache/mustache_template.rb +25 -0
- data/lib/roger_style_guide/templates/mustache/tilt_template.rb +16 -0
- data/lib/roger_style_guide/templates/mustache.rb +9 -0
- data/lib/roger_style_guide/templates.rb +5 -0
- data/lib/roger_style_guide/version.rb +4 -0
- data/lib/roger_style_guide.rb +22 -0
- data/roger_style_guide.gemspec +29 -0
- data/test/unit/test_helper.rb +10 -0
- metadata +193 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 98bf55e4dc2bffd8851fbaeabcd31a7a2571ea52
|
4
|
+
data.tar.gz: dffab5ce3db854d9b124835b625e7a499f4b25a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 912505750d1ba054035deba579085b2c386552b24232a83709557b4ff2124334c3807e1c281b95b6878f9bf22252818017847354cc2fdb688b5ada42654b19d5
|
7
|
+
data.tar.gz: f3dd6cd5fea0992eb85da5aaa8edeba3d0beeef52af399f409c517191a2b63662d8e9a0f56e89ed56f803c3628fdd70676cee98d1c3e31038b6d9f133216c982
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
coverage/
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
LineLength:
|
2
|
+
Description: 'Limit lines to 100 characters.'
|
3
|
+
Max: 100
|
4
|
+
Enabled: true
|
5
|
+
|
6
|
+
StringLiterals:
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Style/DotPosition:
|
11
|
+
EnforcedStyle: trailing
|
12
|
+
Enabled: true
|
13
|
+
|
14
|
+
Metrics/MethodLength:
|
15
|
+
CountComments: false # count full line comments?
|
16
|
+
Max: 20
|
17
|
+
|
18
|
+
Metrics/AbcSize:
|
19
|
+
Max: 20
|
20
|
+
|
21
|
+
Style/ClassAndModuleChildren:
|
22
|
+
EnforcedStyle: compact
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
# By default, the rails cops are not run. Override in project or home
|
26
|
+
# directory .rubocop.yml files, or by giving the -R/--rails option.
|
27
|
+
AllCops:
|
28
|
+
RunRailsCops: false
|
29
|
+
|
30
|
+
# Disabled cops
|
31
|
+
Metrics/ClassLength:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Metrics/ModuleLength:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/EachWithObject:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/AccessorMethodName:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Lint/AssignmentInCondition:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/SingleLineBlockParams:
|
47
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
roger_style_guide (0.1.0)
|
5
|
+
mustache (~> 0.99, >= 0.99.8)
|
6
|
+
roger (~> 1.0, >= 1.7.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.3.0)
|
12
|
+
astrolabe (1.3.1)
|
13
|
+
parser (~> 2.2)
|
14
|
+
codeclimate-test-reporter (1.0.3)
|
15
|
+
simplecov
|
16
|
+
coderay (1.1.1)
|
17
|
+
docile (1.1.5)
|
18
|
+
hpricot (0.8.4)
|
19
|
+
json (1.8.3)
|
20
|
+
metaclass (0.0.4)
|
21
|
+
method_source (0.8.2)
|
22
|
+
mime-types (2.99.3)
|
23
|
+
mocha (1.1.0)
|
24
|
+
metaclass (~> 0.0.1)
|
25
|
+
mustache (0.99.8)
|
26
|
+
parser (2.3.3.0)
|
27
|
+
ast (~> 2.2)
|
28
|
+
power_assert (0.4.1)
|
29
|
+
powerpack (0.1.1)
|
30
|
+
pry (0.10.4)
|
31
|
+
coderay (~> 1.1.0)
|
32
|
+
method_source (~> 0.8.1)
|
33
|
+
slop (~> 3.4)
|
34
|
+
rack (2.0.1)
|
35
|
+
rainbow (2.1.0)
|
36
|
+
rake (10.5.0)
|
37
|
+
redcarpet (3.3.4)
|
38
|
+
roger (1.7.0)
|
39
|
+
hpricot (= 0.8.4)
|
40
|
+
mime-types (~> 2.2)
|
41
|
+
rack (>= 1.0.0)
|
42
|
+
redcarpet (>= 3.1.1)
|
43
|
+
test_construct (~> 2.0)
|
44
|
+
thor (~> 0.19.0)
|
45
|
+
tilt (~> 2.0.1)
|
46
|
+
rubocop (0.31.0)
|
47
|
+
astrolabe (~> 1.3)
|
48
|
+
parser (>= 2.2.2.1, < 3.0)
|
49
|
+
powerpack (~> 0.1)
|
50
|
+
rainbow (>= 1.99.1, < 3.0)
|
51
|
+
ruby-progressbar (~> 1.4)
|
52
|
+
ruby-progressbar (1.8.1)
|
53
|
+
simplecov (0.10.0)
|
54
|
+
docile (~> 1.1.0)
|
55
|
+
json (~> 1.8)
|
56
|
+
simplecov-html (~> 0.10.0)
|
57
|
+
simplecov-html (0.10.0)
|
58
|
+
slop (3.6.0)
|
59
|
+
test-unit (3.1.9)
|
60
|
+
power_assert
|
61
|
+
test_construct (2.0.1)
|
62
|
+
thor (0.19.4)
|
63
|
+
tilt (2.0.5)
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
ruby
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
bundler (~> 1.7)
|
70
|
+
codeclimate-test-reporter (~> 1.0.0)
|
71
|
+
mocha (~> 1.1.0)
|
72
|
+
pry
|
73
|
+
rake (~> 10.0)
|
74
|
+
roger_style_guide!
|
75
|
+
rubocop (~> 0.31.0)
|
76
|
+
simplecov (~> 0.10.0)
|
77
|
+
test-unit (~> 3.1.2)
|
78
|
+
|
79
|
+
BUNDLED WITH
|
80
|
+
1.12.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Digitpaint, Flurin Egger
|
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,74 @@
|
|
1
|
+
# Roger Style Guide
|
2
|
+
|
3
|
+
Helpers to create styleguides.
|
4
|
+
|
5
|
+
## What's in it?
|
6
|
+
|
7
|
+
### Components
|
8
|
+
|
9
|
+
### Generator
|
10
|
+
Quick & easy component generation:
|
11
|
+
|
12
|
+
`roger generate component NAME`
|
13
|
+
|
14
|
+
will generate this structure in your components path:
|
15
|
+
```
|
16
|
+
NAME.html.erb
|
17
|
+
_NAME.html.erb
|
18
|
+
_NAME.scss
|
19
|
+
```
|
20
|
+
|
21
|
+
Options for the command are:
|
22
|
+
|
23
|
+
* `--js` : Will generate a `NAME.js` file too
|
24
|
+
* `--extension=EXT` : Will generate a `_NAME.EXT` instead of `_NAME.html.erb`
|
25
|
+
|
26
|
+
#### Helper
|
27
|
+
The `component` function is simplification of the `partial` function. Taking this directory structure:
|
28
|
+
|
29
|
+
```
|
30
|
+
html
|
31
|
+
|- components
|
32
|
+
|- my_component
|
33
|
+
| |- _my_component.html.erb
|
34
|
+
|- other_component
|
35
|
+
|- _other_component.html.erb
|
36
|
+
|- _other_component_variant.html.erb
|
37
|
+
```
|
38
|
+
|
39
|
+
You can call `component('my_component', a: "b")` which will render the partial `components/my_component/_my_component.html.erb` with locals `{a: "b"}`. If you want to render another componentpartial you can also call `component('other_component/other_component_variant')`.
|
40
|
+
|
41
|
+
The base `components` path can be configured by setting `RogerStyleGuide.components_path` to a path within the HTML directory.
|
42
|
+
|
43
|
+
### Toc
|
44
|
+
The `toc` function is used to display table of contents of your Roger mockup. It's pretty simple: `toc(PATH_TO BUILD TOC FROM)`. See `toc_helper.rb` file for more info on options and lower level function.
|
45
|
+
|
46
|
+
## Mustache
|
47
|
+
Roger Styleguide adds support for Mustache templates including support for components as Mustache partials.
|
48
|
+
|
49
|
+
Rendering mustache templates is just as easy as doing `<%= component("bla") %>` which will render `components/bla/bla.mst` if it exists. If you also have
|
50
|
+
regular partials you can force using the mustache template by doing `<%= component("bla.mst") %>`.
|
51
|
+
|
52
|
+
## Installation
|
53
|
+
|
54
|
+
Add this line to your application's Gemfile:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
gem 'roger_styleguide'
|
58
|
+
```
|
59
|
+
|
60
|
+
And then execute:
|
61
|
+
|
62
|
+
$ bundle
|
63
|
+
|
64
|
+
Or install it yourself as:
|
65
|
+
|
66
|
+
$ gem install roger_styleguide
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it ( https://github.com/digitpaint/roger_style_guide/fork )
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
74
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "rubocop/rake_task"
|
4
|
+
|
5
|
+
task default: [:test, :rubocop]
|
6
|
+
|
7
|
+
desc "Run rubocop"
|
8
|
+
task :rubocop do
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
end
|
11
|
+
|
12
|
+
Rake::TestTask.new do |t|
|
13
|
+
t.libs << "test/unit"
|
14
|
+
t.test_files = FileList["test/unit/**/*_test.rb"]
|
15
|
+
t.verbose = false
|
16
|
+
end
|
File without changes
|
data/lib/roger_style_guide/generators/component/template/_%component_name%.%partial_extension%
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module RogerStyleGuide::Generators
|
2
|
+
# The component generator
|
3
|
+
class ComponentGenerator < Roger::Generators::Base
|
4
|
+
desc "Generate a new component"
|
5
|
+
|
6
|
+
argument :name, type: :string, required: true, desc: "The component name"
|
7
|
+
|
8
|
+
class_option(
|
9
|
+
:components_path,
|
10
|
+
type: :string,
|
11
|
+
desc: "Components path, default: roger.project.html_path/#{RogerStyleGuide.components_path}"
|
12
|
+
)
|
13
|
+
|
14
|
+
class_option(
|
15
|
+
:js,
|
16
|
+
type: :boolean,
|
17
|
+
desc: "Wether or not to generate a component js file",
|
18
|
+
default: false
|
19
|
+
)
|
20
|
+
|
21
|
+
class_option(
|
22
|
+
:extension,
|
23
|
+
type: :string,
|
24
|
+
desc: "The extension of the component partial",
|
25
|
+
default: "html.erb")
|
26
|
+
|
27
|
+
def self.source_root
|
28
|
+
File.dirname(__FILE__) + "/component/template"
|
29
|
+
end
|
30
|
+
|
31
|
+
def do
|
32
|
+
self.destination_root = components_path
|
33
|
+
|
34
|
+
dir_options = {}
|
35
|
+
dir_options[:exclude_pattern] = /.js\Z/ unless options[:js]
|
36
|
+
|
37
|
+
directory(".", component_name, dir_options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def component_name
|
41
|
+
name
|
42
|
+
end
|
43
|
+
|
44
|
+
def partial_extension
|
45
|
+
options[:extension]
|
46
|
+
end
|
47
|
+
|
48
|
+
def components_path
|
49
|
+
options[:components_path] && Pathname.new(options[:components_path]) ||
|
50
|
+
Roger::Cli::Base.project &&
|
51
|
+
Roger::Cli::Base.project.html_path + RogerStyleGuide.components_path
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Roger::Generators.register RogerStyleGuide::Generators::ComponentGenerator
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Compent helper and friends
|
2
|
+
module RogerStyleGuide::Helpers::ComponentHelper
|
3
|
+
# Ease use of components by wrapping the partial helper
|
4
|
+
#
|
5
|
+
# This allows us to call component("map") which will render
|
6
|
+
# RogerStyleGuide.components_path/map/_map.html.erb
|
7
|
+
#
|
8
|
+
# Calling component("map/map") will still work
|
9
|
+
#
|
10
|
+
# Also simplifies passing of locals. It's just the second parameter of
|
11
|
+
# the component helper.
|
12
|
+
def component(path, locals = {}, &block)
|
13
|
+
partial_path = component_template_paths(path).find do |template_path|
|
14
|
+
renderer.send(:find_partial, template_path)
|
15
|
+
end
|
16
|
+
|
17
|
+
renderer.send(:template_not_found!, :component, path) unless partial_path
|
18
|
+
|
19
|
+
# Render the partial
|
20
|
+
partial(partial_path, locals: locals, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def component_template_paths(path)
|
24
|
+
name = File.basename(path)
|
25
|
+
local_name = name.sub(/\A_?/, "_")
|
26
|
+
extension = File.extname(name)[1..-1]
|
27
|
+
name_without_extension = extension ? name.sub(/\.#{Regexp.escape(extension)}\Z/, "") : name
|
28
|
+
|
29
|
+
dir = File.join(
|
30
|
+
RogerStyleGuide.components_path,
|
31
|
+
path.slice(0, path.size - name.size).to_s.strip
|
32
|
+
)
|
33
|
+
|
34
|
+
[
|
35
|
+
# component_path/name/_name.xyz
|
36
|
+
File.join(dir, name_without_extension, local_name),
|
37
|
+
# component_path/name
|
38
|
+
File.join(dir, name)
|
39
|
+
]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Roger::Renderer.helper RogerStyleGuide::Helpers::ComponentHelper
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# Methods for generating Table of Contents
|
2
|
+
module RogerStyleGuide::Helpers::TocHelper
|
3
|
+
# rubocop:disable Metrics/MethodLength,
|
4
|
+
# rubocop:disable Metrics/CyclomaticComplexity,
|
5
|
+
# rubocop:disable Metrics/PerceivedComplexity,
|
6
|
+
# rubocop:disable Metrics/AbcSize
|
7
|
+
|
8
|
+
DEFAULT_MATCH = /html.erb\Z/
|
9
|
+
DEFAULT_MAX_DEPTH = 1000
|
10
|
+
DEFAULT_LINKER = lambda do |url, name, level|
|
11
|
+
"<a href='#{url}' class='level-#{level}' target='fbody'>#{name}</a>"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Generate a table of contents for a certain path getting all files
|
15
|
+
# that match the `match` regexp and go `max_depth` levels deep.
|
16
|
+
#
|
17
|
+
# Options are:
|
18
|
+
#
|
19
|
+
# - match [Regexp] (/html.erb\Z/) What files to match
|
20
|
+
# - max_depth [Integer] (1000) How many directory levels deep should we go
|
21
|
+
# - linker [lambda {|url, name| ... }] A lambda writing out the <a .. > tag.
|
22
|
+
#
|
23
|
+
# Will output html in this structure:
|
24
|
+
#
|
25
|
+
# ```
|
26
|
+
# <ul class="level-0">
|
27
|
+
# <li>
|
28
|
+
# <span class='title-0'>Name</span>
|
29
|
+
# <ul class="level-1">
|
30
|
+
# <li><a href='URL'>NAME</a>
|
31
|
+
# </ul>
|
32
|
+
# </li>
|
33
|
+
# </ul>
|
34
|
+
# ```
|
35
|
+
def toc(path = nil, options = {})
|
36
|
+
options = {
|
37
|
+
match: DEFAULT_MATCH,
|
38
|
+
max_depth: DEFAULT_MAX_DEPTH,
|
39
|
+
linker: DEFAULT_LINKER
|
40
|
+
}.update(options)
|
41
|
+
|
42
|
+
path ||= env["roger.project"].html_path
|
43
|
+
|
44
|
+
tree = traverse_tree(path, options[:max_depth], options[:match])
|
45
|
+
display_tree(tree, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Path will be used to generate the real link
|
49
|
+
# Name_path can be used to use a different string as link name
|
50
|
+
def link_to_template(path, name = nil, level = nil, linker = DEFAULT_LINKER)
|
51
|
+
# Strip of html path
|
52
|
+
url = path.to_s.gsub(env["roger.project"].html_path.to_s, "").gsub(/html\.erb$/, "html")
|
53
|
+
name ||= humanize_path(path)
|
54
|
+
|
55
|
+
linker.call(url, name, level)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Convert path into human readable name
|
59
|
+
def humanize_path(path)
|
60
|
+
File.basename(path).split(".", 2).first.capitalize
|
61
|
+
end
|
62
|
+
|
63
|
+
# Build a tree
|
64
|
+
#
|
65
|
+
# - Path: The path to get the entries from
|
66
|
+
# - Match: Files to match (use regexp). Will only match the File.basename
|
67
|
+
# - Max_depth: How deep should we traverse the tree?
|
68
|
+
# - Level: keep track of how deep we are in the recursino
|
69
|
+
#
|
70
|
+
# @return result = {name: "XX", path: "XX", children: [], type: :file}
|
71
|
+
def traverse_tree(path, max_depth = DFEAULT_MAX_DEPTH, match = DEFAULT_MATCH, level = 0)
|
72
|
+
result = { name: humanize_path(path), path: path, children: [], type: :dir }
|
73
|
+
path = Pathname.new(path)
|
74
|
+
|
75
|
+
# Don't go deeper if we reached max_depth
|
76
|
+
return if level >= max_depth
|
77
|
+
|
78
|
+
path.entries.each do |entry|
|
79
|
+
entry_path = path + entry
|
80
|
+
|
81
|
+
# Normalize paths, removing all "." and "_" files
|
82
|
+
next if entry.to_s.start_with?(".") || entry.to_s.start_with?("_")
|
83
|
+
|
84
|
+
# Check match
|
85
|
+
next if entry_path.file? && !entry.to_s.match(match)
|
86
|
+
|
87
|
+
if entry_path.directory?
|
88
|
+
subdir = traverse_tree(entry_path, max_depth, match, level + 1)
|
89
|
+
|
90
|
+
result[:children] << subdir if subdir
|
91
|
+
else
|
92
|
+
result[:children] << { name: humanize_path(entry), path: path + entry, type: :file }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# If we don't have children we're not going to be visible.
|
97
|
+
return if result[:children].empty?
|
98
|
+
|
99
|
+
result
|
100
|
+
end
|
101
|
+
|
102
|
+
# Display the tree
|
103
|
+
#
|
104
|
+
# @option :linker The linker to use
|
105
|
+
def display_tree(tree, options = {}, level = 0)
|
106
|
+
return "" unless tree
|
107
|
+
|
108
|
+
linker = options[:linker] || DEFAULT_LINKER
|
109
|
+
|
110
|
+
output = []
|
111
|
+
output << "<ul class='level-#{level}'>"
|
112
|
+
|
113
|
+
tree[:children].each do |entry|
|
114
|
+
output << "<li>"
|
115
|
+
if entry[:type] == :file
|
116
|
+
output << link_to_template(entry[:path], entry[:name], level, linker)
|
117
|
+
else
|
118
|
+
if entry[:children].length == 1 &&
|
119
|
+
entry[:children][0][:type] == :file &&
|
120
|
+
entry[:children][0][:name] == entry[:name]
|
121
|
+
output << link_to_template(entry[:children][0][:path], entry[:name], level, linker)
|
122
|
+
else
|
123
|
+
# Check if there is a file exactly named like the current entry.
|
124
|
+
# if there is we'll pluck the file out of the child list and link
|
125
|
+
# the directory entry directly.
|
126
|
+
modified_entry = { children: entry[:children].dup }
|
127
|
+
if child = entry[:children].find { |c| c[:type] == :file && c[:name] == entry[:name] }
|
128
|
+
modified_entry[:children].delete(child)
|
129
|
+
output << link_to_template(child[:path], entry[:name], level, linker)
|
130
|
+
else
|
131
|
+
output << "<span class='title-#{level}'>#{entry[:name]}</span>"
|
132
|
+
end
|
133
|
+
output << display_tree(modified_entry, options, level + 1)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
output << "</li>"
|
137
|
+
end
|
138
|
+
|
139
|
+
output << "</ul>"
|
140
|
+
|
141
|
+
output.join("\n")
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
Roger::Renderer.helper RogerStyleGuide::Helpers::TocHelper
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "mustache"
|
2
|
+
|
3
|
+
module RogerStyleGuide::Templates::Mustache
|
4
|
+
# Mustach template wrapper which handles partial
|
5
|
+
# resolving.
|
6
|
+
class MustacheTemplate < ::Mustache
|
7
|
+
def render(template, data, template_context = nil)
|
8
|
+
@template_context = template_context
|
9
|
+
super(template, data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def partial(name)
|
13
|
+
path = @template_context.component_template_paths(name.to_s + ".mst").find do |template_path|
|
14
|
+
result = @template_context.renderer.send(:find_partial, template_path)
|
15
|
+
break result if result
|
16
|
+
end
|
17
|
+
|
18
|
+
if path
|
19
|
+
File.read(path)
|
20
|
+
else
|
21
|
+
fail "No such Mustache partial found: #{name}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "tilt/template"
|
2
|
+
|
3
|
+
module RogerStyleGuide::Templates::Mustache
|
4
|
+
# Tile template wrapper for our Mustache template
|
5
|
+
class TiltTemplate < ::Tilt::Template
|
6
|
+
def prepare
|
7
|
+
@mustache = MustacheTemplate.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def evaluate(scope, locals)
|
11
|
+
@mustache.render(data, locals, scope)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Tilt.register RogerStyleGuide::Templates::Mustache::TiltTemplate, "mst"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# All generators related namespace
|
2
|
+
module RogerStyleGuide::Templates::Mustache
|
3
|
+
end
|
4
|
+
|
5
|
+
require File.dirname(__FILE__) + "/mustache/mustache_template"
|
6
|
+
require File.dirname(__FILE__) + "/mustache/tilt_template"
|
7
|
+
|
8
|
+
# Tell Roger to treat .mst as generating html output
|
9
|
+
Roger::Resolver::EXTENSION_MAP["html"] << "mst"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
# Toplevel module for all things concerning RogerStyleGuide
|
4
|
+
module RogerStyleGuide
|
5
|
+
# The path within project.html_path where the components reside
|
6
|
+
def self.components_path=(path)
|
7
|
+
@components_path = Pathname.new(path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.components_path
|
11
|
+
@components_path || "components"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Helpers
|
16
|
+
require File.dirname(__FILE__) + "/roger_style_guide/helpers"
|
17
|
+
|
18
|
+
# Generators
|
19
|
+
require File.dirname(__FILE__) + "/roger_style_guide/generators"
|
20
|
+
|
21
|
+
# Templates
|
22
|
+
require File.dirname(__FILE__) + "/roger_style_guide/templates"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "roger_style_guide/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "roger_style_guide"
|
7
|
+
spec.version = RogerStyleGuide::VERSION
|
8
|
+
|
9
|
+
spec.authors = ["Flurin Egger"]
|
10
|
+
spec.email = ["flurin@digitpaint.nl"]
|
11
|
+
spec.summary = "Styleguide plugin for Roger"
|
12
|
+
spec.homepage = "https://github.com/DigitPaint/roger_style_guide"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "roger", "~> 1.0", ">= 1.7.0"
|
21
|
+
spec.add_dependency "mustache", "~> 0.99", ">= 0.99.8"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "mocha", "~> 1.1.0"
|
26
|
+
spec.add_development_dependency "test-unit", "~> 3.1.2"
|
27
|
+
spec.add_development_dependency "simplecov", "~> 0.10.0"
|
28
|
+
spec.add_development_dependency "rubocop", "~> 0.31.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: roger_style_guide
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Flurin Egger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: roger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.7.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.7.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mustache
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.99'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.99.8
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.99'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.99.8
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: bundler
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.7'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.7'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rake
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '10.0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '10.0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: mocha
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.1.0
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.1.0
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: test-unit
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 3.1.2
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 3.1.2
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: simplecov
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 0.10.0
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 0.10.0
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: rubocop
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 0.31.0
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 0.31.0
|
137
|
+
description:
|
138
|
+
email:
|
139
|
+
- flurin@digitpaint.nl
|
140
|
+
executables: []
|
141
|
+
extensions: []
|
142
|
+
extra_rdoc_files: []
|
143
|
+
files:
|
144
|
+
- ".gitignore"
|
145
|
+
- ".rubocop.yml"
|
146
|
+
- Gemfile
|
147
|
+
- Gemfile.lock
|
148
|
+
- LICENSE.txt
|
149
|
+
- README.md
|
150
|
+
- Rakefile
|
151
|
+
- lib/roger_style_guide.rb
|
152
|
+
- lib/roger_style_guide/generators.rb
|
153
|
+
- lib/roger_style_guide/generators/component/template/%component_name%.html.erb.tt
|
154
|
+
- lib/roger_style_guide/generators/component/template/%component_name%.js
|
155
|
+
- lib/roger_style_guide/generators/component/template/_%component_name%.%partial_extension%
|
156
|
+
- lib/roger_style_guide/generators/component/template/_%component_name%.scss
|
157
|
+
- lib/roger_style_guide/generators/component_generator.rb
|
158
|
+
- lib/roger_style_guide/helpers.rb
|
159
|
+
- lib/roger_style_guide/helpers/component_helper.rb
|
160
|
+
- lib/roger_style_guide/helpers/toc_helper.rb
|
161
|
+
- lib/roger_style_guide/templates.rb
|
162
|
+
- lib/roger_style_guide/templates/mustache.rb
|
163
|
+
- lib/roger_style_guide/templates/mustache/mustache_template.rb
|
164
|
+
- lib/roger_style_guide/templates/mustache/tilt_template.rb
|
165
|
+
- lib/roger_style_guide/version.rb
|
166
|
+
- roger_style_guide.gemspec
|
167
|
+
- test/unit/test_helper.rb
|
168
|
+
homepage: https://github.com/DigitPaint/roger_style_guide
|
169
|
+
licenses:
|
170
|
+
- MIT
|
171
|
+
metadata: {}
|
172
|
+
post_install_message:
|
173
|
+
rdoc_options: []
|
174
|
+
require_paths:
|
175
|
+
- lib
|
176
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 2.5.1
|
189
|
+
signing_key:
|
190
|
+
specification_version: 4
|
191
|
+
summary: Styleguide plugin for Roger
|
192
|
+
test_files:
|
193
|
+
- test/unit/test_helper.rb
|