pieces 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41e373bc09582ab8cd1f6570d3dc1ccf4f4b5a9a
4
- data.tar.gz: a9d90b77069ed8841a53b258b5b5f52aa1a48aa4
3
+ metadata.gz: f5c6d9b8bcb0697d6c423f8c4b0384f9a2447da9
4
+ data.tar.gz: ced9731402a01a9b90fd3cd6da37d388bf8b923c
5
5
  SHA512:
6
- metadata.gz: 90cff1166feeddfcb32dcfb5cb808aba8db81a1a8292331392c05641e430561bd530f566304746a31d474e0ecada34b0be8b44ae72b475b94996737ad426213f
7
- data.tar.gz: 8cdb3e0ff52be0e084bd53455024f77e47b3c1d9b8dc4d36502cfe26c2a00953f3807a1724dcca2a1fb6e672d7b95431162b0e3c57403a1b67e278c332609216
6
+ metadata.gz: 0fb1c9f4a23dcddbefcb2e3f8be7e55758a8ab4d663c5db15dca6356c32ec24e8ec5254f6fa19bcc1ca584e27ce6bc1f776e019b48cd036132fb9d87b22e4b7a
7
+ data.tar.gz: 6888e909ec27028bf25633f5fef74370dc2176b6e69d6284baebb6a280ce4fc59d2611d2311771f315443752ed159593bee92a5b32ae5ba8b2ed1a0e6bce1818
data/README.md CHANGED
@@ -61,7 +61,7 @@ For example, `.article` should be defined like so.
61
61
 
62
62
  You can use `.css`, `.scss`, `.sass` and `.less` with Pieces.
63
63
 
64
- **`app/views/layouts/application.html.erb`:**
64
+ **`app/views/layouts/pieces.html.erb`:**
65
65
 
66
66
  ``` erb
67
67
  <html>
@@ -82,7 +82,7 @@ nested components and data to be used to generate a static site.
82
82
  ``` yml
83
83
  index:
84
84
  _pieces:
85
- - layouts/application:
85
+ - layouts/pieces:
86
86
  title: 'My Articles'
87
87
  _pieces:
88
88
  - article: { title: 'A title', content: '<p>Content.</p>' }
@@ -97,7 +97,7 @@ pieces server
97
97
  ```
98
98
 
99
99
  Now visit [http://localhost:8080](http://localhost:8080) to see your site! If
100
- you change your `config/routes.yml` or views they will be reflected on the site.
100
+ you change your `config/pieces.yml` or views they will be reflected on the site.
101
101
 
102
102
  ## Use as styleguide for rails
103
103
 
@@ -111,15 +111,7 @@ Next you need to initialize your application to use Pieces:
111
111
 
112
112
  ```
113
113
  bundle
114
- bundle exec pieces init
115
- ```
116
-
117
- Now mount Pieces in your `config/routes.rb`:
118
-
119
- ``` ruby
120
- Rails.application.routes.draw do
121
- mount Pieces::Rails.new.mount, at: '/styleguide'
122
- end
114
+ bundle exec rails g pieces:rails:install
123
115
  ```
124
116
 
125
117
  Edit your `config/pieces.yml` to demo some of your components.
@@ -132,14 +124,6 @@ bundle exec rails s
132
124
 
133
125
  And then visit [http://localhost:3000/styleguide](http://localhost:3000/styleguide)
134
126
 
135
- Alternatively you can run your styleguide without rails:
136
-
137
- ```
138
- bundle exec pieces s
139
- ```
140
-
141
- And then visit [http://localhost:8080](http://localhost:8080)
142
-
143
127
  ## Create new static site
144
128
 
145
129
  To create a new static site with Pieces:
@@ -229,7 +213,7 @@ You can place your content in a layout quite easily with nested pieces.
229
213
  ``` yml
230
214
  about:
231
215
  _pieces:
232
- - layouts/application:
216
+ - layouts/pieces:
233
217
  _pieces:
234
218
  - header: {}
235
219
  - copy/intro: {}
@@ -239,7 +223,7 @@ about:
239
223
 
240
224
  The child pieces will be rendered in order and passed into the parent
241
225
  "layouts/application" piece as `yield`. If you had
242
- `app/views/layouts/application.html.erb` then you can call yield like so:
226
+ `app/views/layouts/pieces.html.erb` then you can call yield like so:
243
227
 
244
228
  ``` erb
245
229
  <html>
File without changes
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree ./components
3
+ */
@@ -1,12 +1,10 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title><%= title %></title>
5
- <link rel="stylesheet" href="compiled.css" />
6
- </head>
7
- <body>
8
-
9
- <%= yield %>
10
-
11
- </body>
3
+ <head>
4
+ <title><%= title %></title>
5
+ <%= stylesheet_link_tag '/assets/pieces' %>
6
+ </head>
7
+ <body>
8
+ <%= yield %>
9
+ </body>
12
10
  </html>
@@ -6,4 +6,4 @@ index:
6
6
  _pieces:
7
7
  - layouts/pieces:
8
8
  _pieces:
9
- - header: {}
9
+ - _header: {}
@@ -13,17 +13,28 @@ module Pieces
13
13
  def initialize(config)
14
14
  @path = config[:path]
15
15
  @route_config ||= YAML.load_file("#{path}/config/pieces.yml")
16
+ require 'pieces/tilt_extension'
16
17
  end
17
18
 
18
19
  def build
19
- require 'pieces/tilt_extension'
20
- save_files(build_files)
20
+ save_files(_build_routes(_build_styles))
21
+ end
22
+
23
+ def build_styles
24
+ save_files(_build_styles)
25
+ end
26
+
27
+ def build_routes
28
+ save_files(_build_routes)
21
29
  end
22
30
 
23
31
  private
24
32
 
25
- def build_files
26
- files = StyleCompiler.new(path: path).compile({})
33
+ def _build_styles(files = {})
34
+ StyleCompiler.new(path: path).compile(files)
35
+ end
36
+
37
+ def _build_routes(files = {})
27
38
  route_compiler = RouteCompiler.new(path: path, globals: route_config['_global'])
28
39
 
29
40
  routes.reduce(files) do |files, (name, route)|
@@ -1,9 +1,11 @@
1
1
  module Pieces
2
2
  class Listener
3
3
  attr_reader :path
4
+ attr_reader :build_method
4
5
 
5
6
  def initialize(config = {})
6
7
  @path = config[:path] || Dir.pwd
8
+ @build_method = config[:build_method] || :build
7
9
  build_pieces
8
10
  end
9
11
 
@@ -18,7 +20,7 @@ module Pieces
18
20
  private
19
21
 
20
22
  def build_pieces
21
- Pieces::Builder.build(path: path)
23
+ Pieces::Builder.new(path: path).send(build_method)
22
24
  end
23
25
  end
24
26
  end
@@ -0,0 +1,28 @@
1
+ module Pieces
2
+ class Rails
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path('../../../../examples', __FILE__)
5
+
6
+ def pieces_yml
7
+ copy_file 'rails_app/config/pieces.yml', 'config/pieces.yml'
8
+ end
9
+
10
+ def stylesheet
11
+ copy_file 'rails_app/app/assets/stylesheets/pieces.css', 'app/assets/stylesheets/pieces.css'
12
+ end
13
+
14
+ def views
15
+ copy_file 'rails_app/app/views/layouts/pieces.html.erb', 'app/views/layouts/pieces.html.erb'
16
+ copy_file 'rails_app/app/views/application/_header.html.erb', 'app/views/application/_header.html.erb'
17
+ end
18
+
19
+ def mount_styleguide
20
+ route "mount Pieces::Rails.new.mount, at: '/styleguide' unless Rails.env.production?"
21
+ end
22
+
23
+ def gitignore
24
+ append_to_file '.gitignore', 'build/'
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ module Pieces
2
+ class Rails
3
+ class Railtie < ::Rails::Railtie
4
+ generators do
5
+ require 'pieces/rails/install_generator'
6
+ end
7
+ end
8
+ end
9
+ end
data/lib/pieces/rails.rb CHANGED
@@ -1,8 +1,10 @@
1
+ require 'pieces/rails/railtie'
2
+
1
3
  module Pieces
2
4
  class Rails
3
5
  def mount(options = {})
4
6
  path = options[:path] || Dir.pwd
5
- Pieces::Listener.new(path: path).listen
7
+ Pieces::Listener.new(path: path, build_method: :build_routes).listen
6
8
  Pieces::Server.new(options.merge(path: path)).app
7
9
  end
8
10
  end
@@ -1,3 +1,3 @@
1
1
  module Pieces
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
data/lib/pieces.rb CHANGED
@@ -4,7 +4,7 @@ require 'pieces/builder'
4
4
  require 'pieces/generator'
5
5
  require 'pieces/listener'
6
6
  require 'pieces/server'
7
- require 'pieces/rails'
7
+ require 'pieces/rails' if defined?(Rails)
8
8
  require 'pieces/version'
9
9
 
10
10
  module Pieces
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.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Morton
@@ -168,6 +168,7 @@ files:
168
168
  - README.md
169
169
  - Rakefile
170
170
  - bin/pieces
171
+ - examples/boilerplate/.gitignore
171
172
  - examples/boilerplate/Gemfile
172
173
  - examples/boilerplate/app/views/application/footer.html.erb
173
174
  - examples/boilerplate/app/views/application/header.html.erb
@@ -187,13 +188,14 @@ files:
187
188
  - examples/rails_app/app/assets/javascripts/application.js
188
189
  - examples/rails_app/app/assets/stylesheets/application.css
189
190
  - examples/rails_app/app/assets/stylesheets/components/header.css
191
+ - examples/rails_app/app/assets/stylesheets/pieces.css
190
192
  - examples/rails_app/app/controllers/application_controller.rb
191
193
  - examples/rails_app/app/controllers/concerns/.keep
192
194
  - examples/rails_app/app/helpers/application_helper.rb
193
195
  - examples/rails_app/app/mailers/.keep
194
196
  - examples/rails_app/app/models/.keep
195
197
  - examples/rails_app/app/models/concerns/.keep
196
- - examples/rails_app/app/views/application/header.html.erb
198
+ - examples/rails_app/app/views/application/_header.html.erb
197
199
  - examples/rails_app/app/views/layouts/application.html.erb
198
200
  - examples/rails_app/app/views/layouts/pieces.html.erb
199
201
  - examples/rails_app/bin/bundle
@@ -238,6 +240,8 @@ files:
238
240
  - lib/pieces/generator.rb
239
241
  - lib/pieces/listener.rb
240
242
  - lib/pieces/rails.rb
243
+ - lib/pieces/rails/install_generator.rb
244
+ - lib/pieces/rails/railtie.rb
241
245
  - lib/pieces/server.rb
242
246
  - lib/pieces/tilt/css.rb
243
247
  - lib/pieces/tilt/mustache.rb