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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd176c28e444501f000b658818bf1ae701fa5a12
4
- data.tar.gz: 5949e839b62e968d2adb00e17a5d85a110ab2ae8
3
+ metadata.gz: ce469759e0fa76551899ce44f51dc326806302b5
4
+ data.tar.gz: 6691693a1c9f4ffc925bd1849081534d2d960837
5
5
  SHA512:
6
- metadata.gz: b0a5169dc1346fc056c6ffdd9fc184a37eb41586a4d89f86c7c05cbf2bec328f28d502d4725b252329f68263cdae86218187ff255873403e3b2cdccd60bad873
7
- data.tar.gz: 0d26d18a75598d1dfc9298ca35ee2b518526bfd697a0146ff33f86a38f09cec8e9edc1a8a89fe4f144f47d515596a591ec91a2abeaf1346b22845ea92e8f787b
6
+ metadata.gz: 519fea1fef10f8bae83f2ce61a877a64d112d0a94c6c0fe4e0c6325a66e4092bd0326d5489597a546405b809cde2466bd6d878a0743675aaad75e1c887f78e97
7
+ data.tar.gz: 93008bb9f863ba0d56ba67e54fa6d513913e853f203fd192e9c6b2b028c92255f1c97bb134dddc95c5f3b9022786a9b84e2ce8b1fc603ff7cc2d296e98872f0e
data/bin/pieces CHANGED
@@ -14,4 +14,5 @@ when 'build'
14
14
  puts 'done.'
15
15
  else
16
16
  puts 'Run either `pieces init` or `pieces build`'
17
+ exit(1)
17
18
  end
@@ -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
- pieces:
10
- - post:
11
- title: 'A block title'
12
- content: '<p>Some paragraph</p>'
13
- - post:
14
- title: 'Another'
15
- content: '<p>Another thing.</p>'
16
- - post:
17
- title: 'And another'
18
- content: '<p>Blah blah blah.</p>'
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
- pieces:
24
- - post:
25
- title: 'About Author'
26
- content: '<p>He is a cool dude.</p>'
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: {}
@@ -0,0 +1,3 @@
1
+ <footer>
2
+ {{footer_text}}
3
+ </footer>
@@ -0,0 +1,3 @@
1
+ <header>
2
+ <%= self['title'] %>
3
+ </header>
@@ -6,10 +6,6 @@
6
6
  </head>
7
7
 
8
8
  <body>
9
- {{{contents}}}
10
-
11
- <footer>
12
- {{footer_text}}
13
- </footer>
9
+ {{{yield}}}
14
10
  </body>
15
11
  </html>
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ <div class="posts">
2
+ <%= yield %>
3
+ </div>
data/lib/pieces.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'pieces/version'
2
2
  require 'pieces/builder'
3
3
  require 'pieces/generator'
4
+ require 'pieces/tilt_extension'
4
5
 
5
6
  module Pieces
6
7
  end
@@ -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
- files = routes.reduce({}) { |files, (name, route)| build_route(files, name, route) }
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['pieces'].reduce(files) do |files, piece|
26
+ route['_pieces'].reduce(files) do |files, piece|
33
27
  piece, data = piece.keys.first, piece.values.first
34
- route_globals = globals.merge(route.delete('_global') || {})
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
- Dir["pieces/#{piece}/*"].each do |file|
37
- case File.extname(file)
38
- when '.mustache'
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
@@ -2,7 +2,10 @@ module Pieces
2
2
  class Generator
3
3
  def init(config)
4
4
  FileUtils.mkdir_p(config[:path])
5
- Dir["#{example_path}/{config,layouts,pieces}"].each { |dir| FileUtils.cp_r(dir, config[:path]) }
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
@@ -0,0 +1,6 @@
1
+ require 'tilt'
2
+
3
+ module Tilt
4
+ register_lazy :MustacheTemplate, 'tilt/mustache', 'mustache', 'ms'
5
+ register_lazy :CssTemplate, 'tilt/css', 'css'
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Pieces
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/tilt/css.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'tilt/plain'
2
+
3
+ module Tilt
4
+ class CssTemplate < PlainTemplate
5
+ end
6
+ end
@@ -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 'mustache'
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.1.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-07-29 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: mustache
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: :runtime
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: bundler
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/layouts/layout.html.mustache
89
- - example/pieces/post/post.css
90
- - example/pieces/post/post.html.mustache
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: