pieces 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pieces +1 -0
- data/example/config/routes.yml +25 -16
- data/example/pieces/application/footer.html.mustache +3 -0
- data/example/pieces/application/header.html.erb +3 -0
- data/example/{layouts → pieces/layouts}/layout.html.mustache +1 -5
- data/example/pieces/{post → posts}/post.css +0 -0
- data/example/pieces/{post → posts}/post.html.mustache +0 -0
- data/example/pieces/posts/posts.html.erb +3 -0
- data/lib/pieces.rb +1 -0
- data/lib/pieces/builder.rb +27 -31
- data/lib/pieces/generator.rb +4 -1
- data/lib/pieces/tilt_extension.rb +6 -0
- data/lib/pieces/version.rb +1 -1
- data/lib/tilt/css.rb +6 -0
- data/lib/tilt/mustache.rb +13 -0
- data/pieces.gemspec +3 -1
- metadata +42 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce469759e0fa76551899ce44f51dc326806302b5
|
4
|
+
data.tar.gz: 6691693a1c9f4ffc925bd1849081534d2d960837
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 519fea1fef10f8bae83f2ce61a877a64d112d0a94c6c0fe4e0c6325a66e4092bd0326d5489597a546405b809cde2466bd6d878a0743675aaad75e1c887f78e97
|
7
|
+
data.tar.gz: 93008bb9f863ba0d56ba67e54fa6d513913e853f203fd192e9c6b2b028c92255f1c97bb134dddc95c5f3b9022786a9b84e2ce8b1fc603ff7cc2d296e98872f0e
|
data/bin/pieces
CHANGED
data/example/config/routes.yml
CHANGED
@@ -1,26 +1,35 @@
|
|
1
1
|
_global:
|
2
2
|
title_suffix: 'Your Site'
|
3
|
-
|
4
|
-
_layout: 'layout'
|
3
|
+
footer_text: 'Hey'
|
5
4
|
|
6
5
|
index:
|
7
6
|
_global:
|
8
7
|
title: 'Home'
|
9
|
-
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
8
|
+
_pieces:
|
9
|
+
- layouts/layout:
|
10
|
+
_pieces:
|
11
|
+
- header: {}
|
12
|
+
- posts:
|
13
|
+
_pieces:
|
14
|
+
- posts/post:
|
15
|
+
title: 'A block title'
|
16
|
+
content: '<p>Some paragraph</p>'
|
17
|
+
- posts/post:
|
18
|
+
title: 'Another'
|
19
|
+
content: '<p>Another thing.</p>'
|
20
|
+
- posts/post:
|
21
|
+
title: 'And another'
|
22
|
+
content: '<p>Blah blah blah.</p>'
|
23
|
+
- footer: {}
|
19
24
|
|
20
25
|
about:
|
21
26
|
_global:
|
22
27
|
title: 'About'
|
23
|
-
|
24
|
-
-
|
25
|
-
|
26
|
-
|
28
|
+
_pieces:
|
29
|
+
- layouts/layout:
|
30
|
+
_pieces:
|
31
|
+
- header: {}
|
32
|
+
- posts/post:
|
33
|
+
title: 'About Author'
|
34
|
+
content: '<p>He is a cool dude.</p>'
|
35
|
+
- footer: {}
|
File without changes
|
File without changes
|
data/lib/pieces.rb
CHANGED
data/lib/pieces/builder.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
require 'mustache'
|
3
2
|
|
4
3
|
module Pieces
|
5
4
|
class Builder
|
6
5
|
def build(config)
|
7
6
|
Dir.chdir(config[:path]) do
|
8
|
-
|
9
|
-
save_files(render_files_in_layout(files))
|
7
|
+
save_files(routes.reduce({}) { |files, (name, route)| build_route(files, name, route) })
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
@@ -16,10 +14,6 @@ module Pieces
|
|
16
14
|
@route_config ||= YAML.load_file('config/routes.yml')
|
17
15
|
end
|
18
16
|
|
19
|
-
def layout_path
|
20
|
-
"layouts/#{route_config['_layout']}.html.mustache"
|
21
|
-
end
|
22
|
-
|
23
17
|
def globals
|
24
18
|
route_config['_global'] or {}
|
25
19
|
end
|
@@ -29,25 +23,41 @@ module Pieces
|
|
29
23
|
end
|
30
24
|
|
31
25
|
def build_route(files, name, route)
|
32
|
-
route['
|
26
|
+
route['_pieces'].reduce(files) do |files, piece|
|
33
27
|
piece, data = piece.keys.first, piece.values.first
|
34
|
-
|
28
|
+
data['_global'] = globals.merge(route.delete('_global') || {}).merge(data['_global'] || {})
|
29
|
+
|
30
|
+
Dir["pieces/*/*.{css,scss,sass,less}"].each do |file|
|
31
|
+
files['compiled.css'] = { contents: '', type: 'css', compiled: [] } unless files.has_key?('compiled.css')
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
files["#{name}.html"] = { contents: '', type: 'mustache' } unless files.has_key?("#{name}.html")
|
40
|
-
files["#{name}.html"][:contents] << Mustache.render(File.read(file), route_globals.merge(data))
|
41
|
-
when '.css'
|
42
|
-
files['compiled.css'] = { contents: '', type: 'css' } unless files.has_key?('compiled.css')
|
43
|
-
files['compiled.css'][:contents] << File.read(file)
|
33
|
+
unless files['compiled.css'][:compiled].include?(file)
|
34
|
+
files['compiled.css'][:contents] << Tilt.new(file).render
|
35
|
+
files['compiled.css'][:compiled] << file
|
44
36
|
end
|
45
37
|
end
|
46
38
|
|
39
|
+
files["#{name}.html"] = { contents: '', type: 'html' } unless files.has_key?("#{name}.html")
|
40
|
+
content = Tilt.new(piece_path(piece)).render(data['_global'].merge(data)) { yield_route_pieces(data) }
|
41
|
+
files["#{name}.html"][:contents] << content
|
42
|
+
|
47
43
|
files
|
48
44
|
end
|
49
45
|
end
|
50
46
|
|
47
|
+
def piece_path(piece)
|
48
|
+
Dir["pieces/{#{piece},#{piece}/#{piece},application/#{piece}}.html.*"].first
|
49
|
+
end
|
50
|
+
|
51
|
+
def yield_route_pieces(parent_data)
|
52
|
+
return '' unless parent_data.has_key?('_pieces')
|
53
|
+
|
54
|
+
parent_data['_pieces'].reduce('') do |content, piece|
|
55
|
+
piece, data = piece.keys.first, piece.values.first
|
56
|
+
data['_global'] = (parent_data['_global'] || {}).merge(data['_global'] || {})
|
57
|
+
content << Tilt.new(piece_path(piece)).render(data['_global'].merge(data)) { yield_route_pieces(data) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
51
61
|
def save_files(files)
|
52
62
|
FileUtils.rm_rf('build')
|
53
63
|
Dir.mkdir('build')
|
@@ -57,19 +67,5 @@ module Pieces
|
|
57
67
|
def save_file(name, file)
|
58
68
|
File.open("build/#{name}", 'w') { |f| f.write(file[:contents]) }
|
59
69
|
end
|
60
|
-
|
61
|
-
def render_in_layout(contents)
|
62
|
-
Mustache.render(File.read(layout_path), globals.merge(contents: contents))
|
63
|
-
end
|
64
|
-
|
65
|
-
def render_files_in_layout(files)
|
66
|
-
files.reduce({}) do |files, (name, file)|
|
67
|
-
if file[:type] == 'mustache'
|
68
|
-
file[:contents] = render_in_layout(file[:contents])
|
69
|
-
end
|
70
|
-
|
71
|
-
files.merge(name => file)
|
72
|
-
end
|
73
|
-
end
|
74
70
|
end
|
75
71
|
end
|
data/lib/pieces/generator.rb
CHANGED
@@ -2,7 +2,10 @@ module Pieces
|
|
2
2
|
class Generator
|
3
3
|
def init(config)
|
4
4
|
FileUtils.mkdir_p(config[:path])
|
5
|
-
|
5
|
+
|
6
|
+
Dir["#{example_path}/{config,layouts,pieces}"].each do |dir|
|
7
|
+
FileUtils.cp_r(dir, config[:path])
|
8
|
+
end
|
6
9
|
end
|
7
10
|
|
8
11
|
private
|
data/lib/pieces/version.rb
CHANGED
data/lib/tilt/css.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'mustache'
|
2
|
+
|
3
|
+
module Tilt
|
4
|
+
class MustacheTemplate < Template
|
5
|
+
def initialize_engine; end
|
6
|
+
|
7
|
+
def prepare; end
|
8
|
+
|
9
|
+
def evaluate(scope, locals, &block)
|
10
|
+
Mustache.render(data, locals.merge(scope.is_a?(Hash) ? scope : {}).merge(:yield => block.nil? ? '' : block.call))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/pieces.gemspec
CHANGED
@@ -16,9 +16,11 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.executables = ['pieces']
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
|
19
|
-
spec.add_dependency '
|
19
|
+
spec.add_dependency 'tilt', '~> 2.0.1'
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler'
|
22
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
23
|
+
spec.add_development_dependency 'mustache'
|
22
24
|
spec.add_development_dependency 'rake'
|
23
25
|
spec.add_development_dependency 'rspec'
|
24
26
|
end
|
metadata
CHANGED
@@ -1,23 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pieces
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Morton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: tilt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
33
|
version: '0'
|
20
|
-
type: :
|
34
|
+
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
@@ -25,7 +39,21 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: codeclimate-test-reporter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mustache
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - ">="
|
@@ -85,13 +113,19 @@ files:
|
|
85
113
|
- Rakefile
|
86
114
|
- bin/pieces
|
87
115
|
- example/config/routes.yml
|
88
|
-
- example/
|
89
|
-
- example/pieces/
|
90
|
-
- example/pieces/
|
116
|
+
- example/pieces/application/footer.html.mustache
|
117
|
+
- example/pieces/application/header.html.erb
|
118
|
+
- example/pieces/layouts/layout.html.mustache
|
119
|
+
- example/pieces/posts/post.css
|
120
|
+
- example/pieces/posts/post.html.mustache
|
121
|
+
- example/pieces/posts/posts.html.erb
|
91
122
|
- lib/pieces.rb
|
92
123
|
- lib/pieces/builder.rb
|
93
124
|
- lib/pieces/generator.rb
|
125
|
+
- lib/pieces/tilt_extension.rb
|
94
126
|
- lib/pieces/version.rb
|
127
|
+
- lib/tilt/css.rb
|
128
|
+
- lib/tilt/mustache.rb
|
95
129
|
- pieces.gemspec
|
96
130
|
homepage: https://github.com/drpheltright/pieces
|
97
131
|
licenses:
|