pieces 0.2.3 → 0.2.4
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 +4 -4
- data/bin/pieces +2 -14
- data/lib/pieces.rb +3 -1
- data/lib/pieces/builder.rb +24 -48
- data/lib/pieces/cli.rb +20 -0
- data/lib/pieces/compilers/route_compiler.rb +42 -0
- data/lib/pieces/compilers/style_compiler.rb +19 -0
- data/lib/pieces/generator.rb +8 -5
- data/lib/pieces/version.rb +1 -1
- data/pieces.gemspec +1 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef88dd45bb8a84d1b98ea3ec868532c80a8ddec2
|
4
|
+
data.tar.gz: d879f16096b632ce1ead38a69ff11bd45da962bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dd85e804b3d6dbc9815f24466040e568d3b271d62f5690d96ae7c09a57870e1b08a508defc562c7d7b72f765c32cced51b915d03f52a7ca7612de51989116c9
|
7
|
+
data.tar.gz: 4526624987dc7b634928bacfca58709c99998f26c093e6c7c67f3b08065da174837511894ce906652d7b4c8d769f3b8be869595749b20b369bfb00007fa4c01b
|
data/bin/pieces
CHANGED
@@ -1,18 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
|
-
require 'pieces'
|
4
|
+
require 'pieces/cli'
|
5
5
|
|
6
|
-
|
7
|
-
when 'init'
|
8
|
-
init_path = ARGV[1] || '.'
|
9
|
-
Pieces::Generator.new.init(path: init_path)
|
10
|
-
puts "Pieces placed in #{init_path}"
|
11
|
-
when 'build'
|
12
|
-
print 'Building pieces into current directory...'
|
13
|
-
Pieces::Builder.new.build(path: '.')
|
14
|
-
puts 'done.'
|
15
|
-
else
|
16
|
-
puts 'Run either `pieces init` or `pieces build`'
|
17
|
-
exit(1)
|
18
|
-
end
|
6
|
+
Pieces::CLI.start(ARGV)
|
data/lib/pieces.rb
CHANGED
data/lib/pieces/builder.rb
CHANGED
@@ -3,70 +3,46 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
module Pieces
|
5
5
|
class Builder
|
6
|
-
def build(config)
|
7
|
-
|
8
|
-
save_files(routes.reduce({}) { |files, (name, route)| build_route(files, name, route) })
|
9
|
-
end
|
6
|
+
def self.build(config)
|
7
|
+
new(config).build
|
10
8
|
end
|
11
9
|
|
12
|
-
|
10
|
+
attr_reader :path
|
11
|
+
attr_reader :route_config
|
13
12
|
|
14
|
-
def
|
15
|
-
@
|
13
|
+
def initialize(config)
|
14
|
+
@path = config[:path]
|
15
|
+
@route_config ||= YAML.load_file("#{path}/config/routes.yml")
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
18
|
+
def build
|
19
|
+
save_files(build_files)
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
route_config.reject { |key, _| key =~ /^_/ }
|
24
|
-
end
|
25
|
-
|
26
|
-
def build_route(files, name, route)
|
27
|
-
route['_pieces'].reduce(files) do |files, piece|
|
28
|
-
piece, data = piece.keys.first, piece.values.first
|
29
|
-
data['_global'] = globals.merge(route.delete('_global') || {}).merge(data['_global'] || {})
|
30
|
-
|
31
|
-
Dir["pieces/*/*.{css,scss,sass,less}"].each do |file|
|
32
|
-
files['compiled.css'] = { contents: '', type: 'css', compiled: [] } unless files.has_key?('compiled.css')
|
33
|
-
|
34
|
-
unless files['compiled.css'][:compiled].include?(file)
|
35
|
-
files['compiled.css'][:contents] << Tilt.new(file).render
|
36
|
-
files['compiled.css'][:compiled] << file
|
37
|
-
end
|
38
|
-
end
|
22
|
+
private
|
39
23
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
24
|
+
def build_files
|
25
|
+
files = {}
|
26
|
+
StyleCompiler.new(path: path).compile(files)
|
27
|
+
route_compiler = RouteCompiler.new(path: path, globals: route_config['_global'])
|
44
28
|
|
45
|
-
|
29
|
+
routes.reduce(files) do |files, (name, route)|
|
30
|
+
route_compiler.compile(files, name, route)
|
46
31
|
end
|
47
32
|
end
|
48
33
|
|
49
|
-
def
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
def yield_route_pieces(parent_data)
|
54
|
-
return '' unless parent_data.has_key?('_pieces')
|
55
|
-
|
56
|
-
parent_data['_pieces'].reduce('') do |content, piece|
|
57
|
-
piece, data = piece.keys.first, piece.values.first
|
58
|
-
data['_global'] = (parent_data['_global'] || {}).merge(data['_global'] || {})
|
59
|
-
view_model = OpenStruct.new(data['_global'].merge(data))
|
60
|
-
content << Tilt.new(piece_path(piece)).render(view_model) { yield_route_pieces(data) }
|
61
|
-
end
|
34
|
+
def routes
|
35
|
+
route_config.reject { |key, _| key =~ /^_/ }
|
62
36
|
end
|
63
37
|
|
64
38
|
def save_files(files)
|
65
|
-
|
66
|
-
|
39
|
+
Dir.chdir(path) do
|
40
|
+
FileUtils.rm_rf('build')
|
41
|
+
Dir.mkdir('build')
|
67
42
|
|
68
|
-
|
69
|
-
|
43
|
+
files.each do |name, file|
|
44
|
+
save_file(name, file)
|
45
|
+
end
|
70
46
|
end
|
71
47
|
end
|
72
48
|
|
data/lib/pieces/cli.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'pieces'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
module Pieces
|
5
|
+
class CLI < Thor
|
6
|
+
desc 'init DIR', 'create new pieces app in DIR'
|
7
|
+
def init(path = '.')
|
8
|
+
print "Placing new pieces in #{path}... "
|
9
|
+
Pieces::Generator.init(path: path)
|
10
|
+
puts 'done.'
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'build DIR', 'build pieces in DIR'
|
14
|
+
def build(path = '.')
|
15
|
+
print "Building pieces into #{path}... "
|
16
|
+
Pieces::Builder.build(path: path)
|
17
|
+
puts 'done.'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Pieces
|
2
|
+
class RouteCompiler
|
3
|
+
attr_reader :path
|
4
|
+
attr_reader :globals
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
@path = config[:path] || Dir.pwd
|
8
|
+
@globals = config[:globals] || {}
|
9
|
+
end
|
10
|
+
|
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
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def piece_path(piece)
|
28
|
+
Dir["#{path}/pieces/{#{piece},#{piece}/#{piece},application/#{piece}}.html.*"].first
|
29
|
+
end
|
30
|
+
|
31
|
+
def yield_route_pieces(parent_data)
|
32
|
+
return '' unless parent_data.has_key?('_pieces')
|
33
|
+
|
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) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Pieces
|
2
|
+
class StyleCompiler
|
3
|
+
attr_reader :path
|
4
|
+
|
5
|
+
def initialize(config = {})
|
6
|
+
@path = config[:path] || Dir.pwd
|
7
|
+
end
|
8
|
+
|
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
|
14
|
+
end
|
15
|
+
|
16
|
+
files
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/pieces/generator.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
module Pieces
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
module Generator
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def init(config = {})
|
6
|
+
path = config[:path] || Dir.pwd
|
7
|
+
FileUtils.mkdir_p(path)
|
5
8
|
|
6
9
|
Dir["#{example_path}/{config,layouts,pieces}"].each do |dir|
|
7
|
-
FileUtils.cp_r(dir,
|
10
|
+
FileUtils.cp_r(dir, path)
|
8
11
|
end
|
9
12
|
|
10
|
-
FileUtils.cp("#{example_path}/Gemfile", "#{
|
13
|
+
FileUtils.cp("#{example_path}/Gemfile", "#{path}/Gemfile")
|
11
14
|
end
|
12
15
|
|
13
16
|
private
|
data/lib/pieces/version.rb
CHANGED
data/pieces.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
|
19
19
|
spec.add_dependency 'tilt', '~> 2.0.1'
|
20
|
+
spec.add_dependency 'thor', '~> 0.19.1'
|
20
21
|
|
21
22
|
spec.add_development_dependency 'bundler'
|
22
23
|
spec.add_development_dependency 'codeclimate-test-reporter'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pieces
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
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-08-
|
11
|
+
date: 2015-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.19.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.19.1
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +154,9 @@ files:
|
|
140
154
|
- examples/original/pieces/posts/posts.html.erb
|
141
155
|
- lib/pieces.rb
|
142
156
|
- lib/pieces/builder.rb
|
157
|
+
- lib/pieces/cli.rb
|
158
|
+
- lib/pieces/compilers/route_compiler.rb
|
159
|
+
- lib/pieces/compilers/style_compiler.rb
|
143
160
|
- lib/pieces/generator.rb
|
144
161
|
- lib/pieces/tilt_extension.rb
|
145
162
|
- lib/pieces/version.rb
|