pieces 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +81 -25
- data/examples/boilerplate/{pieces → app/views}/application/footer.html.erb +0 -0
- data/examples/boilerplate/{pieces → app/views}/application/header.html.erb +0 -0
- data/examples/boilerplate/{pieces → app/views}/layouts/application.html.erb +0 -0
- data/examples/boilerplate/config/{routes.yml → pieces.yml} +0 -0
- data/examples/original/{pieces → app/views}/application/footer.html.mustache +0 -0
- data/examples/original/{pieces → app/views}/application/header.html.erb +0 -0
- data/examples/original/{pieces → app/views}/layouts/layout.html.mustache +0 -0
- data/examples/original/{pieces → app/views}/posts/post.css +0 -0
- data/examples/original/{pieces → app/views}/posts/post.html.mustache +0 -0
- data/examples/original/{pieces → app/views}/posts/posts.html.erb +0 -0
- data/examples/original/config/{routes.yml → pieces.yml} +0 -0
- data/lib/pieces/builder.rb +2 -3
- data/lib/pieces/cli.rb +7 -0
- data/lib/pieces/compilers/route_compiler.rb +23 -19
- data/lib/pieces/compilers/style_compiler.rb +4 -6
- data/lib/pieces/generator.rb +1 -1
- data/lib/pieces/version.rb +1 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc6517c3ea0a591bb7a6deafc161937aa4eb5be4
|
4
|
+
data.tar.gz: 04508f264f041cd126949f8c18e583713dc1e0e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da143a39a6e03b46ae92e8770c27838b34513438a8bcedeb60e838434beb8d2ef2723f1a973dd152b7a71ea720872d8b7c88ad39ef0bf75d1f81c2809910e874
|
7
|
+
data.tar.gz: 5a2d32331d1093236b0c32be2a3993e0669f028c6bdb8a3be46f3051af9081d6b7ed3d74afa5fc8e4e372537d89c4f4ab8cf4292125e78d14186c7589e662ee1
|
data/README.md
CHANGED
@@ -5,40 +5,95 @@
|
|
5
5
|
[![Test Coverage](https://codeclimate.com/github/drpheltright/pieces/badges/coverage.svg)](https://codeclimate.com/github/drpheltright/pieces/coverage)
|
6
6
|
|
7
7
|
This gem will take your HTML and CSS components and compile them into a static
|
8
|
-
site.
|
8
|
+
site.
|
9
9
|
|
10
|
-
|
10
|
+
- Build static sites and blogs
|
11
|
+
- Produce styleguides for your rails applications
|
12
|
+
- Mock up designs
|
11
13
|
|
12
|
-
|
14
|
+
## Define your HTML and CSS together
|
15
|
+
|
16
|
+
With pieces, you define the view of your application with components. Even
|
17
|
+
your layout is just another component.
|
18
|
+
|
19
|
+
### Installation
|
20
|
+
|
21
|
+
If installing pieces into a rails app, add it to your Gemfile:
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
gem 'pieces'
|
25
|
+
```
|
26
|
+
|
27
|
+
If building a standalone site, install globally:
|
13
28
|
|
14
29
|
```
|
15
30
|
gem install pieces
|
16
|
-
pieces init hello_world
|
17
31
|
```
|
18
32
|
|
19
|
-
|
33
|
+
### Quick example
|
20
34
|
|
21
|
-
|
35
|
+
Let's start by defining some "pieces", or views as they are better known in
|
36
|
+
the rails world.
|
22
37
|
|
23
|
-
|
38
|
+
**`app/views/article/article.html.erb`:**
|
24
39
|
|
25
|
-
```
|
26
|
-
|
40
|
+
``` erb
|
41
|
+
<article class="article">
|
42
|
+
<h1 class="article__title"><%= title %></h1>
|
43
|
+
<div class="article__content"><%= content %></div>
|
44
|
+
</article>
|
45
|
+
```
|
46
|
+
|
47
|
+
**`app/views/layouts/application.html.erb`:**
|
48
|
+
|
49
|
+
``` erb
|
50
|
+
<html>
|
51
|
+
<head>
|
52
|
+
<title>{{title}}</title>
|
53
|
+
</head>
|
54
|
+
<body>
|
55
|
+
<%= yield %>
|
56
|
+
</body>
|
57
|
+
</html>
|
58
|
+
```
|
59
|
+
|
60
|
+
We pull the pieces together with a configuration file. Here you can define
|
61
|
+
nested pieces and data to be used to generate a static site.
|
62
|
+
|
63
|
+
**`config/pieces.yml`:**
|
64
|
+
|
65
|
+
``` yml
|
66
|
+
index:
|
67
|
+
_pieces:
|
68
|
+
- layouts/application:
|
69
|
+
title: 'My Articles'
|
70
|
+
_pieces:
|
71
|
+
- article: { title: 'A title', content: '<p>Content.</p>' }
|
72
|
+
- article: { title: 'Another title', content: '<p>More content.</p>' }
|
27
73
|
```
|
28
74
|
|
29
|
-
|
75
|
+
With these three files in place and having installed pieces on your system
|
76
|
+
(`gem install pieces`) you can run:
|
30
77
|
|
31
78
|
```
|
32
|
-
|
33
|
-
pieces init styleguide
|
79
|
+
pieces build
|
34
80
|
```
|
35
81
|
|
36
|
-
This will
|
82
|
+
This will build HTML and CSS into `build/`.
|
83
|
+
|
84
|
+
## Create new static site
|
85
|
+
|
86
|
+
To create a new static site with pieces:
|
87
|
+
|
88
|
+
```
|
89
|
+
gem install pieces
|
90
|
+
pieces init hello_world
|
91
|
+
```
|
37
92
|
|
38
|
-
|
93
|
+
This will install `config/pieces.yml`, a layout and example header and footer
|
94
|
+
into `hello_world/` for you.
|
39
95
|
|
40
|
-
|
41
|
-
and routes for your site all you have to do is run:
|
96
|
+
Once you've built the pieces and routes for your site all you have to do is run:
|
42
97
|
|
43
98
|
```
|
44
99
|
pieces build
|
@@ -46,12 +101,12 @@ pieces build
|
|
46
101
|
|
47
102
|
Make sure you run this from your pieces directory!
|
48
103
|
|
49
|
-
##
|
104
|
+
## Configuration
|
50
105
|
|
51
|
-
Using configuration found in `config/
|
106
|
+
Using configuration found in `config/pieces.yml` pieces will compile your
|
52
107
|
modular components ala BEM (or whatever you prefer) into a static HTML site.
|
53
108
|
|
54
|
-
At the top level of your `
|
109
|
+
At the top level of your `pieces.yml` you define your output files, or "routes".
|
55
110
|
The following example will build both `index.html` and `about.html`.
|
56
111
|
|
57
112
|
``` yml
|
@@ -65,9 +120,9 @@ about:
|
|
65
120
|
```
|
66
121
|
|
67
122
|
Both `index.html` and `about.html` make use of a piece called "intro". This
|
68
|
-
piece will be found in either `
|
69
|
-
or `
|
70
|
-
[tilt](https://github.com/rtomayko/tilt).
|
123
|
+
piece will be found in either `app/views/intro.html.*`,
|
124
|
+
`app/views/intro/intro.html.*` or `app/views/application/intro.html.*`. The `*`
|
125
|
+
can be any format supported by [tilt](https://github.com/rtomayko/tilt).
|
71
126
|
|
72
127
|
You can generate your HTML into directories quite easily:
|
73
128
|
|
@@ -93,8 +148,9 @@ about:
|
|
93
148
|
- footer: {}
|
94
149
|
```
|
95
150
|
|
96
|
-
"copy/intro" and "galleries/photo" will be found in
|
97
|
-
and `
|
151
|
+
"copy/intro" and "galleries/photo" will be found in
|
152
|
+
`app/views/copy/intro.html.*` and `app/views/galleries/photo.html.*`
|
153
|
+
respectively.
|
98
154
|
|
99
155
|
You can place your content in a layout quite easily with nested pieces.
|
100
156
|
|
@@ -111,7 +167,7 @@ about:
|
|
111
167
|
|
112
168
|
The child pieces will be rendered in order and passed into the parent
|
113
169
|
"layouts/application" piece as `yield`. If you had
|
114
|
-
`
|
170
|
+
`app/views/layouts/application.html.erb` then you can call yield like so:
|
115
171
|
|
116
172
|
``` erb
|
117
173
|
<html>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/pieces/builder.rb
CHANGED
@@ -12,7 +12,7 @@ module Pieces
|
|
12
12
|
|
13
13
|
def initialize(config)
|
14
14
|
@path = config[:path]
|
15
|
-
@route_config ||= YAML.load_file("#{path}/config/
|
15
|
+
@route_config ||= YAML.load_file("#{path}/config/pieces.yml")
|
16
16
|
end
|
17
17
|
|
18
18
|
def build
|
@@ -22,8 +22,7 @@ module Pieces
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def build_files
|
25
|
-
files = {}
|
26
|
-
StyleCompiler.new(path: path).compile(files)
|
25
|
+
files = StyleCompiler.new(path: path).compile({})
|
27
26
|
route_compiler = RouteCompiler.new(path: path, globals: route_config['_global'])
|
28
27
|
|
29
28
|
routes.reduce(files) do |files, (name, route)|
|
data/lib/pieces/cli.rb
CHANGED
@@ -9,33 +9,37 @@ module Pieces
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def compile(files, name, route)
|
12
|
-
|
13
|
-
piece, data = piece.keys.first, piece.values.first
|
14
|
-
data['_global'] = globals.merge(route.delete('_global') || {}).merge(data['_global'] || {})
|
15
|
-
|
16
|
-
files["#{name}.html"] = { contents: '', type: 'html' } unless files.has_key?("#{name}.html")
|
17
|
-
view_model = OpenStruct.new(data['_global'].merge(data))
|
18
|
-
content = Tilt.new(piece_path(piece)).render(view_model) { yield_route_pieces(data) }
|
19
|
-
files["#{name}.html"][:contents] << content
|
20
|
-
|
21
|
-
files
|
22
|
-
end
|
12
|
+
files.merge("#{name}.html" => { contents: yield_pieces(route), type: 'html' })
|
23
13
|
end
|
24
14
|
|
25
15
|
private
|
26
16
|
|
27
17
|
def piece_path(piece)
|
28
|
-
Dir["#{path}/
|
18
|
+
Dir["#{path}/app/views/{#{piece},#{piece}/#{piece},application/#{piece}}.html.*"].first
|
29
19
|
end
|
30
20
|
|
31
|
-
def
|
32
|
-
|
21
|
+
def route_globals(route)
|
22
|
+
globals.merge(route['_global'] || {})
|
23
|
+
end
|
24
|
+
|
25
|
+
def merge_globals(data, route)
|
26
|
+
data.merge('_global' => route_globals(route).merge(data['_global'] || {}))
|
27
|
+
end
|
28
|
+
|
29
|
+
def pieces(data)
|
30
|
+
(data['_pieces'] || []).map do |piece|
|
31
|
+
[piece.keys.first, merge_globals(piece.values.first, data)]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def compile_piece(piece, data)
|
36
|
+
view_model = OpenStruct.new(data['_global'].merge(data))
|
37
|
+
Tilt.new(piece_path(piece)).render(view_model) { yield_pieces(data) }
|
38
|
+
end
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
view_model = OpenStruct.new(data['_global'].merge(data))
|
38
|
-
content << Tilt.new(piece_path(piece)).render(view_model) { yield_route_pieces(data) }
|
40
|
+
def yield_pieces(data)
|
41
|
+
pieces(data).reduce('') do |contents, (piece, data)|
|
42
|
+
contents << compile_piece(piece, data)
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
@@ -7,13 +7,11 @@ module Pieces
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def compile(files)
|
10
|
-
files
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
files.merge('compiled.css' => { contents: '', type: 'css' }).tap do |files|
|
11
|
+
Dir["#{path}/app/views/*/*.{css,scss,sass,less}"].each do |file|
|
12
|
+
files['compiled.css'][:contents] << Tilt.new(file).render
|
13
|
+
end
|
14
14
|
end
|
15
|
-
|
16
|
-
files
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
data/lib/pieces/generator.rb
CHANGED
data/lib/pieces/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pieces
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Morton
|
@@ -141,17 +141,17 @@ files:
|
|
141
141
|
- Rakefile
|
142
142
|
- bin/pieces
|
143
143
|
- examples/boilerplate/Gemfile
|
144
|
-
- examples/boilerplate/
|
145
|
-
- examples/boilerplate/
|
146
|
-
- examples/boilerplate/
|
147
|
-
- examples/boilerplate/pieces
|
148
|
-
- examples/original/
|
149
|
-
- examples/original/
|
150
|
-
- examples/original/
|
151
|
-
- examples/original/
|
152
|
-
- examples/original/
|
153
|
-
- examples/original/
|
154
|
-
- examples/original/pieces
|
144
|
+
- examples/boilerplate/app/views/application/footer.html.erb
|
145
|
+
- examples/boilerplate/app/views/application/header.html.erb
|
146
|
+
- examples/boilerplate/app/views/layouts/application.html.erb
|
147
|
+
- examples/boilerplate/config/pieces.yml
|
148
|
+
- examples/original/app/views/application/footer.html.mustache
|
149
|
+
- examples/original/app/views/application/header.html.erb
|
150
|
+
- examples/original/app/views/layouts/layout.html.mustache
|
151
|
+
- examples/original/app/views/posts/post.css
|
152
|
+
- examples/original/app/views/posts/post.html.mustache
|
153
|
+
- examples/original/app/views/posts/posts.html.erb
|
154
|
+
- examples/original/config/pieces.yml
|
155
155
|
- lib/pieces.rb
|
156
156
|
- lib/pieces/builder.rb
|
157
157
|
- lib/pieces/cli.rb
|