middleman-patterns 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.rubocop.yml +12 -0
- data/Gemfile +17 -0
- data/LICENSE +22 -0
- data/README.md +83 -0
- data/Rakefile +16 -0
- data/lib/middleman-patterns/helpers.rb +137 -0
- data/lib/middleman-patterns.rb +37 -0
- data/lib/middleman_extension.rb +3 -0
- data/middleman-patterns.gemspec +23 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5e5479560dfbf3d84ba888602e12ef1d9ff462b
|
4
|
+
data.tar.gz: e44d850b59e9100f7216d093ae66fa7359076baf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e68baa7075ae06f5b94fd5aa663c21747abdf70a181008c150b850fa23f8063cf558c4b58c0a2fb252c54bd45d68974fac5258657e3a30a78522233fdfdbb10c
|
7
|
+
data.tar.gz: 413b5d771c5ffdf978e223ea65d3e18e4c41f37ecd05f4931dc519e8b2bedb892dec46a096b2c53a078d4e968679be2690f1084be9909097eacc8588c0e76fb4
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# If you do not have OpenSSL installed, update
|
4
|
+
# the following line to use "http://" instead
|
5
|
+
source 'https://rubygems.org'
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in middleman-patterns.gemspec
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
group :development do
|
11
|
+
gem 'yard', '~> 0.8.7'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'rubocop', '~> 0.28'
|
16
|
+
gem 'simplecov', '~> 0.9' require: false
|
17
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Bearded
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Pattern Man
|
2
|
+
A middleman extension that implements [Pattern Lab-style](http://patternlab.io) patterns.
|
3
|
+
|
4
|
+
### Installation
|
5
|
+
|
6
|
+
You'll need to install this gem first.
|
7
|
+
|
8
|
+
* put `gem install 'middleman-patterns'` in the Gemfile of your middleman project
|
9
|
+
* run `bundle install`
|
10
|
+
* add `activate :patterns` to your `config.rb` file outside the `configure :build` block
|
11
|
+
|
12
|
+
|
13
|
+
You're up and running! This gem supports whatever templating engines middleman supports, but you do need to put the template files for patterns where this extension can find them. The expected default directory structure looks like the following (filenames are examples):
|
14
|
+
|
15
|
+
```
|
16
|
+
source/
|
17
|
+
patterns/
|
18
|
+
templates/
|
19
|
+
user-information.html.erb
|
20
|
+
organisms/
|
21
|
+
address-input.html.erb
|
22
|
+
molecules/
|
23
|
+
labeled-input.html.erb
|
24
|
+
atoms/
|
25
|
+
button.html.erb
|
26
|
+
```
|
27
|
+
|
28
|
+
### Using Patterns
|
29
|
+
|
30
|
+
Put some HTML in your patterns:
|
31
|
+
|
32
|
+
```html+ruby
|
33
|
+
# patterns/molecules/labeled-input.html.erb
|
34
|
+
---
|
35
|
+
input_class: 'input'
|
36
|
+
---
|
37
|
+
|
38
|
+
<div class="<%=input_class%>">
|
39
|
+
<label for="<%=input_id%>">
|
40
|
+
<%= label_text %>
|
41
|
+
</label>
|
42
|
+
<%= atom 'input' %>
|
43
|
+
</div>
|
44
|
+
```
|
45
|
+
|
46
|
+
```html+ruby
|
47
|
+
# patterns/atoms/input.html.erb
|
48
|
+
---
|
49
|
+
input_type: text
|
50
|
+
---
|
51
|
+
<input type="<%= input_type %>" <% if input_id %> id="<%= input_id %>" <% end %>>
|
52
|
+
```
|
53
|
+
|
54
|
+
Then use the appropriate helper method in your middleman view:
|
55
|
+
|
56
|
+
```html+ruby
|
57
|
+
# source/index.html.erb
|
58
|
+
|
59
|
+
<div class="welcome">
|
60
|
+
<%= molecule 'labeled-input', input_id: 'some_input', label_text: "Fill me out!" %>
|
61
|
+
</div>
|
62
|
+
```
|
63
|
+
|
64
|
+
And your output will be:
|
65
|
+
|
66
|
+
```html
|
67
|
+
<div class="welcome">
|
68
|
+
<div class="input">
|
69
|
+
<label for="some_input">
|
70
|
+
Fill me out!
|
71
|
+
</label>
|
72
|
+
<input type="text" id="some_input">
|
73
|
+
</div>
|
74
|
+
</div>
|
75
|
+
```
|
76
|
+
|
77
|
+
### Config options
|
78
|
+
|
79
|
+
You can customize the patterns directory by passing `patterns_directory: 'other_directory'` when activating the extension.
|
80
|
+
|
81
|
+
By default, this extension ignores everything in the `patterns` directory when building the site, so you don't end up with pages with URLs like `/patterns/atoms/button.html`. You can override this so that the site *does* build these pages if you want, by passing the `build_patterns` option.
|
82
|
+
|
83
|
+
`activate :patterns, build_patterns: true`
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require 'cucumber/rake/task'
|
7
|
+
|
8
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
9
|
+
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rake/clean'
|
13
|
+
|
14
|
+
task test: ['cucumber']
|
15
|
+
|
16
|
+
task default: :test
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Middleman
|
3
|
+
module Patterns
|
4
|
+
# These helpers are available in source template files.
|
5
|
+
#
|
6
|
+
# Helpers are defined dynamically to match the pattern types in the
|
7
|
+
# PATTERNS constant.
|
8
|
+
#
|
9
|
+
# These pattern calls all work identically except for the path the extension
|
10
|
+
# checks for the source file (based on pattern type).
|
11
|
+
#
|
12
|
+
# Variables are available in patterns and can come from one of three places:
|
13
|
+
#
|
14
|
+
# * Front matter in the pattern file itself
|
15
|
+
# * locals passed to the pattern
|
16
|
+
# * locals that were passed into the currently-rendering pattern
|
17
|
+
#
|
18
|
+
# @example Nested Patterns
|
19
|
+
#
|
20
|
+
# Given the following two patterns for a button:
|
21
|
+
#
|
22
|
+
# # patterns/molecules/buttons.html.erb
|
23
|
+
# ---
|
24
|
+
# div_class: 'button'
|
25
|
+
# ---
|
26
|
+
# <div class="<%= div_class %>">
|
27
|
+
# <%= atom 'button', button_text: 'molecule button' %>
|
28
|
+
# </div>
|
29
|
+
#
|
30
|
+
# --------------------------
|
31
|
+
#
|
32
|
+
# # patterns/atoms/button.html.erb
|
33
|
+
# ---
|
34
|
+
# button_text: I'm a button
|
35
|
+
# ---
|
36
|
+
#
|
37
|
+
# <button type="button"><%= button_text %></button>
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# Variable precendence flows from highest->lowest pattern in terms of nesting,
|
41
|
+
# so a molecule with a local passed which is the same name as application data
|
42
|
+
# variable or front-matter variable will be overridden (div_class above).
|
43
|
+
#
|
44
|
+
# # index.html.erb
|
45
|
+
# <%= molecule 'buttons', div_class: 'big-button' %>
|
46
|
+
# <%= molecule 'buttons', button_text: "Send 1000 emails" %>
|
47
|
+
#
|
48
|
+
# Should render:
|
49
|
+
#
|
50
|
+
# <div class="big-button">
|
51
|
+
# <button type="button">molecule button</button>
|
52
|
+
# </div>
|
53
|
+
#
|
54
|
+
# <div class="button">
|
55
|
+
# <button type="button">Send 1000 emails</button>
|
56
|
+
# </div>
|
57
|
+
#
|
58
|
+
# @see PATTERNS
|
59
|
+
module Helpers
|
60
|
+
PATTERNS = %w(template organism molecule atom)
|
61
|
+
|
62
|
+
# Getter for locals passed into pattern calls.
|
63
|
+
# Allows scoping for variables for nested pattern rendering
|
64
|
+
#
|
65
|
+
# Example: Rendering a molecule template that renders a "Label" atom:
|
66
|
+
#
|
67
|
+
# Calling as `molecule 'labeled-input', label_class: 'optional'`
|
68
|
+
# will override the atom's label_class local, even though in the molecule's template
|
69
|
+
# the label atom will be called without explicitly setting the label_class.
|
70
|
+
#
|
71
|
+
# @return [Hash]
|
72
|
+
def context_variables
|
73
|
+
@context_variables ||= {}
|
74
|
+
@context_variables
|
75
|
+
end
|
76
|
+
|
77
|
+
PATTERNS.each do |type|
|
78
|
+
# define helper methods available to templates. They all have the same signature.
|
79
|
+
define_method type do |name, locals = {}, context = self|
|
80
|
+
path = resolve_pattern_path(type, name)
|
81
|
+
|
82
|
+
# keep a copy of our old state
|
83
|
+
old_context = context_variables.dup
|
84
|
+
|
85
|
+
# update our state
|
86
|
+
update_context locals, extensions[:frontmatter].data(path).first
|
87
|
+
|
88
|
+
# render the file (including potentially recursively other patterns)
|
89
|
+
output = render_individual_file(path, context_variables, {}, context)
|
90
|
+
|
91
|
+
# restore our state pre-call
|
92
|
+
@context_variables = old_context
|
93
|
+
|
94
|
+
output
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Get the path to the specified pattern on disk. This respects the config setting
|
99
|
+
# patterns_directory to determine where to look.
|
100
|
+
#
|
101
|
+
# @see {PatternsExtension#patterns_directory}
|
102
|
+
# @param [String] pattern_type The type of pattern
|
103
|
+
# @param [String] pattern_name The name of the pattern (without file extension)
|
104
|
+
# @return [String] The absolute path to the specified pattern on disk.
|
105
|
+
def resolve_pattern_path(pattern_type, pattern_name)
|
106
|
+
path = File.join(config.patterns_directory, pattern_type.pluralize, pattern_name)
|
107
|
+
absolute_path = resolve_template(path)
|
108
|
+
|
109
|
+
unless absolute_path
|
110
|
+
error_message = "#{pattern_type.capitalize} #{pattern_name} not found: #{path}"
|
111
|
+
raise ::Middleman::CoreExtensions::Rendering::TemplateNotFound, error_message
|
112
|
+
end
|
113
|
+
|
114
|
+
absolute_path
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
# Update the contextual variables from the parent pattern
|
120
|
+
#
|
121
|
+
# This handles setting priority between frontmatter data,
|
122
|
+
# locals passed when rendering, and locals passed from the parent pattern.
|
123
|
+
# @param locals [Hash] A set of locals
|
124
|
+
# @return [Mixed]
|
125
|
+
def update_context(locals = {}, frontmatter = {})
|
126
|
+
# This is our currently-passed context
|
127
|
+
old_context = context_variables.dup
|
128
|
+
|
129
|
+
# Override front-matter data with locals
|
130
|
+
new_context = frontmatter.merge(locals)
|
131
|
+
|
132
|
+
# Override the result with anything passed from a higher level
|
133
|
+
@context_variables = new_context.merge(old_context)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'middleman-core'
|
4
|
+
require 'middleman-patterns/helpers'
|
5
|
+
|
6
|
+
# Middleman extension class.
|
7
|
+
# Allows overriding default patterns' directory.
|
8
|
+
# Exposes helper methods in helpers.rb to templates in the middleman app.
|
9
|
+
# Ignores the patterns directory when building the site by default.
|
10
|
+
#
|
11
|
+
# Options:
|
12
|
+
# :patterns_directory
|
13
|
+
# the local directory patterns are stored in, defaults to "patterns"
|
14
|
+
#
|
15
|
+
# :build_patterns
|
16
|
+
# whether or not to ignore the patterns directory when building the site
|
17
|
+
#
|
18
|
+
# @see Middleman::Patterns::Helpers
|
19
|
+
class PatternsExtension < ::Middleman::Extension
|
20
|
+
option :patterns_directory, 'patterns', 'The location of the patterns\' directory'
|
21
|
+
option :build_patterns, false, 'Whether or not to build pages for patterns.'
|
22
|
+
|
23
|
+
self.defined_helpers = [Middleman::Patterns::Helpers]
|
24
|
+
|
25
|
+
def initialize(app, options_hash = {}, &block)
|
26
|
+
super
|
27
|
+
|
28
|
+
app.set :patterns_directory, options.patterns_directory
|
29
|
+
end
|
30
|
+
|
31
|
+
# Handles ignoring the patterns directory during build if this appropriate option is set.
|
32
|
+
def after_configuration
|
33
|
+
@app.ignore(/#{app.config.setting(:patterns_directory).value}\//) unless options.build_patterns
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
PatternsExtension.register(:patterns)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'middleman-patterns'
|
7
|
+
s.version = '0.1'
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Brett Bender']
|
10
|
+
s.email = ['brett@bearded.com']
|
11
|
+
s.homepage = 'http://www.bearded.com'
|
12
|
+
s.summary = 'An implementation of pattern-lab (http://patternlab.io) for middleman'
|
13
|
+
s.description = s.summary
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.licenses = ['MIT']
|
21
|
+
|
22
|
+
s.add_runtime_dependency 'middleman-core', ['~> 3.3', '>= 3.3.7']
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-patterns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brett Bender
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.3.7
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.3.7
|
33
|
+
description: An implementation of pattern-lab (http://patternlab.io) for middleman
|
34
|
+
email:
|
35
|
+
- brett@bearded.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- ".gitignore"
|
41
|
+
- ".rubocop.yml"
|
42
|
+
- Gemfile
|
43
|
+
- LICENSE
|
44
|
+
- README.md
|
45
|
+
- Rakefile
|
46
|
+
- lib/middleman-patterns.rb
|
47
|
+
- lib/middleman-patterns/helpers.rb
|
48
|
+
- lib/middleman_extension.rb
|
49
|
+
- middleman-patterns.gemspec
|
50
|
+
homepage: http://www.bearded.com
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.4.2
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: An implementation of pattern-lab (http://patternlab.io) for middleman
|
74
|
+
test_files: []
|