pieces 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef88dd45bb8a84d1b98ea3ec868532c80a8ddec2
4
- data.tar.gz: d879f16096b632ce1ead38a69ff11bd45da962bc
3
+ metadata.gz: fc6517c3ea0a591bb7a6deafc161937aa4eb5be4
4
+ data.tar.gz: 04508f264f041cd126949f8c18e583713dc1e0e0
5
5
  SHA512:
6
- metadata.gz: 4dd85e804b3d6dbc9815f24466040e568d3b271d62f5690d96ae7c09a57870e1b08a508defc562c7d7b72f765c32cced51b915d03f52a7ca7612de51989116c9
7
- data.tar.gz: 4526624987dc7b634928bacfca58709c99998f26c093e6c7c67f3b08065da174837511894ce906652d7b4c8d769f3b8be869595749b20b369bfb00007fa4c01b
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. Very very alpha.
8
+ site.
9
9
 
10
- ## Create new static site
10
+ - Build static sites and blogs
11
+ - Produce styleguides for your rails applications
12
+ - Mock up designs
11
13
 
12
- To create a new static site with pieces:
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
- This will install some boiler plate in `hello_world/`.
33
+ ### Quick example
20
34
 
21
- ## Create styleguide within existing application
35
+ Let's start by defining some "pieces", or views as they are better known in
36
+ the rails world.
22
37
 
23
- Add pieces to your Gemfile:
38
+ **`app/views/article/article.html.erb`:**
24
39
 
25
- ```ruby
26
- gem 'pieces'
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
- Then run
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
- bundle
33
- pieces init styleguide
79
+ pieces build
34
80
  ```
35
81
 
36
- This will install pieces inside a subfolder called `styleguide/`.
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
- ## Building your site
93
+ This will install `config/pieces.yml`, a layout and example header and footer
94
+ into `hello_world/` for you.
39
95
 
40
- Please follow examples for a howto right now. Once you've built the pieces
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
- ## How it works
104
+ ## Configuration
50
105
 
51
- Using configuration found in `config/routes.yml` pieces will compile your
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 `routes.yml` you define your output files, or "routes".
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 `pieces/intro.html.*`, `pieces/intro/intro.html.*`
69
- or `pieces/application/intro.html.*`. The `*` can be any format supported by
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 `pieces/copy/intro.html.*`
97
- and `pieces/galleries/photo.html.*` respectively.
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
- `pieces/layouts/application.html.erb` then you can call yield like so:
170
+ `app/views/layouts/application.html.erb` then you can call yield like so:
115
171
 
116
172
  ``` erb
117
173
  <html>
@@ -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/routes.yml")
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)|
@@ -16,5 +16,12 @@ module Pieces
16
16
  Pieces::Builder.build(path: path)
17
17
  puts 'done.'
18
18
  end
19
+
20
+ map %w[--version -v] => :version
21
+
22
+ desc '--version', 'get pieces version'
23
+ def version
24
+ puts "pieces v#{Pieces::VERSION}"
25
+ end
19
26
  end
20
27
  end
@@ -9,33 +9,37 @@ module Pieces
9
9
  end
10
10
 
11
11
  def compile(files, name, route)
12
- route['_pieces'].reduce(files) do |files, piece|
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}/pieces/{#{piece},#{piece}/#{piece},application/#{piece}}.html.*"].first
18
+ Dir["#{path}/app/views/{#{piece},#{piece}/#{piece},application/#{piece}}.html.*"].first
29
19
  end
30
20
 
31
- def yield_route_pieces(parent_data)
32
- return '' unless parent_data.has_key?('_pieces')
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
- parent_data['_pieces'].reduce('') do |content, piece|
35
- piece, data = piece.keys.first, piece.values.first
36
- data['_global'] = (parent_data['_global'] || {}).merge(data['_global'] || {})
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['compiled.css'] = { contents: '', type: 'css' }
11
-
12
- Dir["#{path}/pieces/*/*.{css,scss,sass,less}"].each do |file|
13
- files['compiled.css'][:contents] << Tilt.new(file).render
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
@@ -6,7 +6,7 @@ module Pieces
6
6
  path = config[:path] || Dir.pwd
7
7
  FileUtils.mkdir_p(path)
8
8
 
9
- Dir["#{example_path}/{config,layouts,pieces}"].each do |dir|
9
+ Dir["#{example_path}/{config,app}"].each do |dir|
10
10
  FileUtils.cp_r(dir, path)
11
11
  end
12
12
 
@@ -1,3 +1,3 @@
1
1
  module Pieces
2
- VERSION = '0.2.4'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.4
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/config/routes.yml
145
- - examples/boilerplate/pieces/application/footer.html.erb
146
- - examples/boilerplate/pieces/application/header.html.erb
147
- - examples/boilerplate/pieces/layouts/application.html.erb
148
- - examples/original/config/routes.yml
149
- - examples/original/pieces/application/footer.html.mustache
150
- - examples/original/pieces/application/header.html.erb
151
- - examples/original/pieces/layouts/layout.html.mustache
152
- - examples/original/pieces/posts/post.css
153
- - examples/original/pieces/posts/post.html.mustache
154
- - examples/original/pieces/posts/posts.html.erb
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