pieces 0.4.5 → 0.5.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 +10 -7
- data/examples/rails_app/Gemfile +1 -30
- data/examples/rails_app/app/assets/javascripts/components/article_summary.coffee +1 -0
- data/examples/rails_app/app/assets/javascripts/pieces.js +1 -0
- data/examples/rails_app/app/views/layouts/pieces.html.erb +1 -0
- data/examples/rails_app/config/pieces.yml +5 -1
- data/examples/rails_app/config/routes.rb +1 -1
- data/lib/pieces.rb +3 -0
- data/lib/pieces/backtrace_formatter.rb +21 -0
- data/lib/pieces/builder.rb +15 -30
- data/lib/pieces/cli.rb +2 -0
- data/lib/pieces/config.rb +52 -0
- data/lib/pieces/configurable.rb +9 -0
- data/lib/pieces/generator.rb +6 -5
- data/lib/pieces/listener.rb +23 -27
- data/lib/pieces/publisher.rb +70 -0
- data/lib/pieces/rails.rb +8 -7
- data/lib/pieces/rails/railtie.rb +2 -0
- data/lib/pieces/{compilers/route_compiler.rb → route_compiler.rb} +8 -10
- data/lib/pieces/server.rb +14 -10
- data/lib/pieces/version.rb +1 -1
- data/pieces.gemspec +6 -0
- metadata +93 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73782cbe81a03c730a6f900907002e7c3c340291
|
4
|
+
data.tar.gz: 053135ed7030f75e618145944d21abddcc308865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cb0ed6e93620de4ead6eb5cb31ed936b434b672a41ed5234c4dc6daf47242a8f59bc2bd205ab2386b00b2333f5a743d7f26c6872958f893b95f59615a511a38
|
7
|
+
data.tar.gz: 116bd25ff96679c855ad792786a1e6df4bb8ec0b5f0913062998b2660dbf6debbdedb4400ab7c5d82e35c4e838eb7194cccdcb105f438bb8676032d43c4bb26a
|
data/README.md
CHANGED
@@ -51,8 +51,8 @@ same places rails does.
|
|
51
51
|
</article>
|
52
52
|
```
|
53
53
|
|
54
|
-
|
55
|
-
For example, `.article` should be defined like so.
|
54
|
+
Ideally you should have a one to one relationship between components, and
|
55
|
+
stylesheets. For example, `.article` should be defined like so.
|
56
56
|
|
57
57
|
**`app/assets/stylesheets/components/article.css`:**
|
58
58
|
|
@@ -66,17 +66,20 @@ For example, `.article` should be defined like so.
|
|
66
66
|
}
|
67
67
|
```
|
68
68
|
|
69
|
-
You can use `.css`, `.scss`, `.sass` and `.less` with Pieces.
|
69
|
+
You can use `.css`, `.scss`, `.sass` and `.less` with Pieces. In fact anything
|
70
|
+
supports by [Sprockets](https://github.com/rails/sprockets) since that is what
|
71
|
+
we use under the hood.
|
70
72
|
|
71
|
-
We also need to pull this stylesheet into
|
73
|
+
We also need to pull this stylesheet into your styleguide. By default pieces
|
74
|
+
will look for `pieces.css`.
|
72
75
|
|
73
|
-
**`app/assets/stylesheets/
|
76
|
+
**`app/assets/stylesheets/pieces.css`:**
|
74
77
|
|
75
78
|
```css
|
76
79
|
/*= require_tree ./components */
|
77
80
|
```
|
78
81
|
|
79
|
-
And a layout to pull
|
82
|
+
And we need a layout to pull the components together.
|
80
83
|
|
81
84
|
**`app/views/layouts/pieces.html.erb`:**
|
82
85
|
|
@@ -165,7 +168,7 @@ And then visit [http://localhost:8080](http://localhost:8080)
|
|
165
168
|
If you do you should update Pieces::Rails in your `config/routes.rb` as follows:
|
166
169
|
|
167
170
|
``` ruby
|
168
|
-
mount Pieces::Rails.
|
171
|
+
mount Pieces::Rails.mount(force_polling: true), at: '/styleguide' unless Rails.env.production?
|
169
172
|
```
|
170
173
|
|
171
174
|
This will tell `listen`, the gem that watches for changes, to poll your app
|
data/examples/rails_app/Gemfile
CHANGED
@@ -2,45 +2,16 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'pieces'
|
4
4
|
|
5
|
-
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
6
5
|
gem 'rails', '4.2.1'
|
7
|
-
# Use sqlite3 as the database for Active Record
|
8
6
|
gem 'sqlite3'
|
9
|
-
# Use SCSS for stylesheets
|
10
7
|
gem 'sass-rails', '~> 5.0'
|
11
|
-
# Use Uglifier as compressor for JavaScript assets
|
12
8
|
gem 'uglifier', '>= 1.3.0'
|
13
|
-
# Use CoffeeScript for .coffee assets and views
|
14
|
-
gem 'coffee-rails', '~> 4.1.0'
|
15
|
-
# See https://github.com/rails/execjs#readme for more supported runtimes
|
16
|
-
# gem 'therubyracer', platforms: :ruby
|
17
|
-
|
18
|
-
# Use jquery as the JavaScript library
|
19
9
|
gem 'jquery-rails'
|
20
|
-
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
21
10
|
gem 'turbolinks'
|
22
|
-
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
23
|
-
gem 'jbuilder', '~> 2.0'
|
24
|
-
# bundle exec rake doc:rails generates the API under doc/api.
|
25
|
-
gem 'sdoc', '~> 0.4.0', group: :doc
|
26
|
-
|
27
|
-
# Use ActiveModel has_secure_password
|
28
|
-
# gem 'bcrypt', '~> 3.1.7'
|
29
|
-
|
30
|
-
# Use Unicorn as the app server
|
31
|
-
# gem 'unicorn'
|
32
|
-
|
33
|
-
# Use Capistrano for deployment
|
34
|
-
# gem 'capistrano-rails', group: :development
|
35
11
|
|
36
12
|
group :development, :test do
|
37
|
-
|
38
|
-
gem 'byebug'
|
39
|
-
|
40
|
-
# Access an IRB console on exception pages or by using <%= console %> in views
|
13
|
+
gem 'pry-byebug'
|
41
14
|
gem 'web-console', '~> 2.0'
|
42
|
-
|
43
|
-
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
44
15
|
gem 'spring'
|
45
16
|
end
|
46
17
|
|
@@ -0,0 +1 @@
|
|
1
|
+
console.log('hello world')
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require_tree ./components
|
@@ -2,6 +2,10 @@ _global:
|
|
2
2
|
title: 'Your Site!!'
|
3
3
|
footer: 'Hey'
|
4
4
|
|
5
|
+
_publish:
|
6
|
+
- type: github
|
7
|
+
remote: https://github.com/drpheltright/pieces.git
|
8
|
+
|
5
9
|
index:
|
6
10
|
_pieces:
|
7
11
|
- layouts/pieces:
|
@@ -11,7 +15,7 @@ index:
|
|
11
15
|
- _branding: {}
|
12
16
|
- articles/_summary:
|
13
17
|
article:
|
14
|
-
title: 'A standard
|
18
|
+
title: 'A standard article summary'
|
15
19
|
excerpt: 'This summary does not deserve any special attention.'
|
16
20
|
- articles/_summary:
|
17
21
|
modifier: '--latest'
|
data/lib/pieces.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Pieces
|
2
|
+
class BacktraceFormatter
|
3
|
+
include Configurable
|
4
|
+
|
5
|
+
def format(exception)
|
6
|
+
output = ["Exception<#{exception.class.name}>: #{exception.message}"]
|
7
|
+
output << ''
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'rails'
|
11
|
+
trace = ::Rails.backtrace_cleaner.clean(exception.backtrace)
|
12
|
+
rescue LoadError => e
|
13
|
+
trace = exception.backtrace
|
14
|
+
# .delete_if { |line| !line.include?(config.path) }
|
15
|
+
# .map { |line| line.sub("#{config.path}/", '') }
|
16
|
+
end
|
17
|
+
|
18
|
+
output.concat(trace.map { |line| " #{line}" }).join("\n")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/pieces/builder.rb
CHANGED
@@ -1,64 +1,49 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
require 'yaml'
|
3
3
|
require 'sprockets'
|
4
|
-
require 'pieces/
|
4
|
+
require 'pieces/route_compiler'
|
5
|
+
require 'pieces/config'
|
5
6
|
require 'pieces/server'
|
6
7
|
require 'pieces/tilt_extension'
|
7
8
|
|
8
9
|
module Pieces
|
9
10
|
class Builder
|
10
|
-
def self.build(config)
|
11
|
-
new(config).build
|
11
|
+
def self.build(config = {})
|
12
|
+
new(Config.new(config)).build
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
attr_reader :route_config
|
15
|
+
include Configurable
|
16
16
|
|
17
17
|
def initialize(config)
|
18
|
-
|
19
|
-
|
20
|
-
unless File.exists?("#{path}/config/pieces.yml")
|
21
|
-
puts "We could not find pieces.yml in #{path}/config/"
|
22
|
-
puts 'Sorry about that!'
|
23
|
-
exit(1)
|
24
|
-
end
|
25
|
-
|
26
|
-
@route_config ||= YAML.load_file("#{path}/config/pieces.yml")
|
18
|
+
super
|
19
|
+
config.env = env
|
27
20
|
end
|
28
21
|
|
29
22
|
def build
|
30
|
-
save_files(build_routes(
|
23
|
+
save_files(build_routes(build_assets))
|
31
24
|
end
|
32
25
|
|
33
26
|
private
|
34
27
|
|
35
28
|
def env
|
36
|
-
@env ||= Server.new(
|
29
|
+
@env ||= Server.new(config).sprockets_env
|
37
30
|
end
|
38
31
|
|
39
|
-
def
|
40
|
-
files.merge('assets/pieces.css' => { type: 'css', contents: env['pieces.css'] }
|
32
|
+
def build_assets(files = {})
|
33
|
+
files.merge('assets/pieces.css' => { type: 'css', contents: env['pieces.css'] },
|
34
|
+
'assets/pieces.js' => { type: 'js', contents: env['pieces.js'] })
|
41
35
|
end
|
42
36
|
|
43
37
|
def build_routes(files = {})
|
44
|
-
route_compiler = RouteCompiler.new(
|
45
|
-
globals: route_config['_global'],
|
46
|
-
env: env)
|
38
|
+
route_compiler = RouteCompiler.new(config)
|
47
39
|
|
48
|
-
routes.reduce(files) do |files, (name, route)|
|
40
|
+
config.routes.reduce(files) do |files, (name, route)|
|
49
41
|
route_compiler.compile(files, name, route)
|
50
42
|
end
|
51
43
|
end
|
52
44
|
|
53
|
-
def routes
|
54
|
-
route_config.reject { |key, _| key =~ /^_/ }
|
55
|
-
end
|
56
|
-
|
57
45
|
def save_files(files)
|
58
|
-
Dir.chdir(path) do
|
59
|
-
FileUtils.rm_rf('build')
|
60
|
-
Dir.mkdir('build')
|
61
|
-
|
46
|
+
Dir.chdir(config.path) do
|
62
47
|
files.each do |name, file|
|
63
48
|
save_file(name, file)
|
64
49
|
end
|
data/lib/pieces/cli.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Pieces
|
2
|
+
class ConfigNotFound < RuntimeError; end
|
3
|
+
class PublisherConfigNotFound < RuntimeError; end
|
4
|
+
|
5
|
+
class Config < Hash
|
6
|
+
attr_reader :path
|
7
|
+
attr_accessor :env
|
8
|
+
|
9
|
+
def initialize(config = {})
|
10
|
+
@path = config[:path] || Dir.pwd
|
11
|
+
load_config! unless config[:load] == false
|
12
|
+
end
|
13
|
+
|
14
|
+
def routes
|
15
|
+
reject { |key, _| key =~ /^_/ }
|
16
|
+
end
|
17
|
+
|
18
|
+
def globals
|
19
|
+
self['_global'] || {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def publish_endpoint
|
23
|
+
if has_key?('_publish')
|
24
|
+
self['_publish'].first
|
25
|
+
else
|
26
|
+
raise PublisherConfigNotFound
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def force_polling?
|
31
|
+
self['_force_polling']
|
32
|
+
end
|
33
|
+
|
34
|
+
def asset_prefix
|
35
|
+
self['_asset_prefix']
|
36
|
+
end
|
37
|
+
|
38
|
+
def reload!
|
39
|
+
load_config!
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def load_config!
|
45
|
+
if File.exists?("#{path}/config/pieces.yml")
|
46
|
+
merge!(YAML.load_file("#{path}/config/pieces.yml"))
|
47
|
+
else
|
48
|
+
raise ConfigNotFound.new("We could not find pieces.yml in #{path}/config/")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/pieces/generator.rb
CHANGED
@@ -3,7 +3,7 @@ require 'thor'
|
|
3
3
|
module Pieces
|
4
4
|
class Generator
|
5
5
|
def self.init(config = {})
|
6
|
-
new(config).init
|
6
|
+
new(Pieces::Config.new(config.merge(load: false))).init
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.from_superclass(method, default)
|
@@ -12,15 +12,16 @@ module Pieces
|
|
12
12
|
|
13
13
|
include Thor::Actions
|
14
14
|
include Thor::Shell
|
15
|
+
include Configurable
|
15
16
|
|
16
17
|
source_root File.expand_path('../../../examples/boilerplate', __FILE__)
|
17
18
|
|
18
|
-
attr_reader :
|
19
|
+
attr_reader :options
|
19
20
|
|
20
|
-
def initialize(config
|
21
|
-
|
21
|
+
def initialize(config)
|
22
|
+
super
|
22
23
|
@options = {}
|
23
|
-
self.destination_root = config
|
24
|
+
self.destination_root = config.path
|
24
25
|
end
|
25
26
|
|
26
27
|
def init
|
data/lib/pieces/listener.rb
CHANGED
@@ -1,54 +1,50 @@
|
|
1
|
+
require 'pieces/backtrace_formatter'
|
2
|
+
|
1
3
|
module Pieces
|
2
4
|
class Listener
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
def self.listen(config = {})
|
6
|
+
new(Config.new(config)).listen
|
7
|
+
end
|
8
|
+
|
9
|
+
include Configurable
|
6
10
|
|
7
11
|
def initialize(config = {})
|
8
|
-
|
9
|
-
@build_method = config[:build_method] || :build
|
10
|
-
@force_polling = config[:force_polling] || false
|
12
|
+
super
|
11
13
|
build_pieces
|
12
14
|
end
|
13
15
|
|
14
16
|
def listen
|
15
|
-
Listen.to(
|
17
|
+
Listen.to(*paths, force_polling: config.force_polling?) do
|
16
18
|
rebuild_pieces
|
17
19
|
end.tap(&:start)
|
18
20
|
end
|
19
21
|
|
20
22
|
private
|
21
23
|
|
24
|
+
def paths
|
25
|
+
["#{config.path}/config", "#{config.path}/app/views"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def backtrace_formatter
|
29
|
+
@backtrace_formatter ||= Pieces::BacktraceFormatter.new(config)
|
30
|
+
end
|
31
|
+
|
22
32
|
def build_pieces
|
23
|
-
Pieces::Builder.new(
|
33
|
+
Pieces::Builder.new(config).build
|
24
34
|
rescue => e
|
25
|
-
|
35
|
+
puts backtrace_formatter.format(e)
|
26
36
|
exit(1)
|
27
37
|
end
|
28
38
|
|
29
39
|
def rebuild_pieces
|
30
|
-
print "\nRebuilding #{File.basename(path)}... "
|
31
|
-
|
40
|
+
print "\nRebuilding #{File.basename(config.path)}... "
|
41
|
+
config.reload!
|
42
|
+
Pieces::Builder.new(config).build
|
32
43
|
puts 'done.'
|
33
44
|
rescue => e
|
34
45
|
puts 'an error occurred.'
|
35
46
|
puts ''
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def output_backtrace(exception)
|
40
|
-
puts "Exception<#{exception.class.name}>: #{exception.message}"
|
41
|
-
puts ''
|
42
|
-
|
43
|
-
if defined?(::Rails)
|
44
|
-
trace = ::Rails.backtrace_cleaner.clean(exception.backtrace)
|
45
|
-
else
|
46
|
-
trace = exception.backtrace
|
47
|
-
.delete_if { |line| !line.include?(path) }
|
48
|
-
.map { |line| line.sub("#{path}/", '') }
|
49
|
-
end
|
50
|
-
|
51
|
-
puts trace.map { |line| " #{line}" }
|
47
|
+
puts backtrace_formatter.format(e)
|
52
48
|
end
|
53
49
|
end
|
54
50
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Pieces
|
4
|
+
class Publisher
|
5
|
+
def self.publish(config)
|
6
|
+
new(Pieces::Config.new(config)).publish
|
7
|
+
end
|
8
|
+
|
9
|
+
include Configurable
|
10
|
+
|
11
|
+
def publish
|
12
|
+
publisher_class.new(config).publish
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def publisher_class
|
18
|
+
self.class.const_get(config.publish_endpoint['type'].capitalize)
|
19
|
+
end
|
20
|
+
|
21
|
+
class Adapter
|
22
|
+
include Configurable
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def asset_prefix
|
27
|
+
end
|
28
|
+
|
29
|
+
def builder
|
30
|
+
config['_asset_prefix'] = asset_prefix
|
31
|
+
Pieces::Builder.new(config)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Github < Adapter
|
36
|
+
def publish
|
37
|
+
FileUtils.rm_rf("#{config.path}/build/")
|
38
|
+
FileUtils.mkdir("#{config.path}/build/")
|
39
|
+
clone_into_build_dir
|
40
|
+
builder.build
|
41
|
+
commit_and_push_changes
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def asset_prefix
|
47
|
+
_, username, repo = URI(config.publish_endpoint['remote']).path.split('/')
|
48
|
+
repo = File.basename(repo, '.git')
|
49
|
+
"http://#{username}.github.io/#{repo}/assets"
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def exec(*commands)
|
55
|
+
system(commands.join(' && '), chdir: "#{config.path}/build/")
|
56
|
+
end
|
57
|
+
|
58
|
+
def clone_into_build_dir
|
59
|
+
exec("git clone -o pieces_github_pages #{config.publish_endpoint['remote']} .",
|
60
|
+
"git checkout gh-pages")
|
61
|
+
end
|
62
|
+
|
63
|
+
def commit_and_push_changes
|
64
|
+
exec("git add .",
|
65
|
+
"git commit -m 'Commit all the things'",
|
66
|
+
"git push pieces_github_pages gh-pages")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/pieces/rails.rb
CHANGED
@@ -3,16 +3,17 @@ require 'pieces/server'
|
|
3
3
|
|
4
4
|
module Pieces
|
5
5
|
class Rails
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@force_polling = options[:force_polling]
|
6
|
+
def self.mount(config = {})
|
7
|
+
config = Config.new(config.merge(path: config[:path] || ::Rails.root,
|
8
|
+
'force_polling' => config[:force_polling]))
|
9
|
+
new(config).mount
|
11
10
|
end
|
12
11
|
|
12
|
+
include Configurable
|
13
|
+
|
13
14
|
def mount
|
14
|
-
|
15
|
-
|
15
|
+
Listener.new(config).listen
|
16
|
+
Server.new(config).app
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
data/lib/pieces/rails/railtie.rb
CHANGED
@@ -2,14 +2,10 @@ require 'ostruct'
|
|
2
2
|
|
3
3
|
module Pieces
|
4
4
|
class RouteCompiler
|
5
|
-
|
6
|
-
attr_reader :env
|
7
|
-
attr_reader :globals
|
5
|
+
include Configurable
|
8
6
|
|
9
7
|
def initialize(config)
|
10
|
-
@
|
11
|
-
@env = config[:env]
|
12
|
-
@globals = config[:globals] || {}
|
8
|
+
@config = config
|
13
9
|
end
|
14
10
|
|
15
11
|
def compile(files, name, route)
|
@@ -19,11 +15,11 @@ module Pieces
|
|
19
15
|
private
|
20
16
|
|
21
17
|
def piece_path(piece)
|
22
|
-
Dir["#{path}/app/views/{#{piece},#{piece}/#{piece},application/#{piece}}.html.*"].first
|
18
|
+
Dir["#{config.path}/app/views/{#{piece},#{piece}/#{piece},application/#{piece}}.html.*"].first
|
23
19
|
end
|
24
20
|
|
25
21
|
def route_globals(route)
|
26
|
-
globals.merge(route['_global'] || {})
|
22
|
+
config.globals.merge(route['_global'] || {})
|
27
23
|
end
|
28
24
|
|
29
25
|
def merge_globals(data, route)
|
@@ -38,7 +34,8 @@ module Pieces
|
|
38
34
|
|
39
35
|
def compile_piece(piece, data)
|
40
36
|
view_model = ViewModel.new(data['_global'].merge(data))
|
41
|
-
view_model.env = env
|
37
|
+
view_model.env = config.env
|
38
|
+
view_model.asset_prefix = config.asset_prefix
|
42
39
|
::Tilt.new(piece_path(piece)).render(view_model) { yield_pieces(data) }
|
43
40
|
end
|
44
41
|
|
@@ -50,6 +47,7 @@ module Pieces
|
|
50
47
|
|
51
48
|
class ViewModel < OpenStruct
|
52
49
|
attr_accessor :env
|
50
|
+
attr_accessor :asset_prefix
|
53
51
|
|
54
52
|
begin
|
55
53
|
require 'action_view'
|
@@ -65,7 +63,7 @@ module Pieces
|
|
65
63
|
|
66
64
|
def compute_asset_path(path, options = {})
|
67
65
|
if env.resolve!(path)
|
68
|
-
File.join('/assets', path)
|
66
|
+
File.join(asset_prefix || '/assets', path)
|
69
67
|
else
|
70
68
|
super
|
71
69
|
end
|
data/lib/pieces/server.rb
CHANGED
@@ -5,20 +5,24 @@ require 'pieces/listener'
|
|
5
5
|
|
6
6
|
module Pieces
|
7
7
|
class Server < Rack::Server
|
8
|
-
|
8
|
+
def self.start(config = {})
|
9
|
+
new(Config.new(config)).start
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
attr_reader :config
|
13
|
+
|
14
|
+
def initialize(config)
|
15
|
+
@config = config
|
16
|
+
super({})
|
13
17
|
end
|
14
18
|
|
15
19
|
def start
|
16
|
-
Pieces::Listener.new(
|
20
|
+
Pieces::Listener.new(config).listen
|
17
21
|
super
|
18
22
|
end
|
19
23
|
|
20
24
|
def sprockets_env
|
21
|
-
Sprockets::Environment.new.tap do |env|
|
25
|
+
Sprockets::Environment.new(config.path).tap do |env|
|
22
26
|
env.append_path 'app/assets/javascripts'
|
23
27
|
env.append_path 'app/assets/stylesheets'
|
24
28
|
env.append_path 'app/views'
|
@@ -26,13 +30,13 @@ module Pieces
|
|
26
30
|
end
|
27
31
|
|
28
32
|
def app
|
29
|
-
urls = files_to_serve(path)
|
30
|
-
build_path = "#{path}/build"
|
33
|
+
urls = files_to_serve(config.path)
|
34
|
+
build_path = "#{config.path}/build"
|
31
35
|
assets_app = sprockets_env
|
32
36
|
|
33
37
|
Rack::Builder.app do
|
34
38
|
use Rack::Reloader
|
35
|
-
use Rack::Static, urls:
|
39
|
+
use Rack::Static, urls: [''], root: build_path, index: 'index.html'
|
36
40
|
map('/assets') { run assets_app } unless defined? ::Rails
|
37
41
|
run Proc.new { |env| [404, {}, ['Not found']] }
|
38
42
|
end
|
@@ -41,7 +45,7 @@ module Pieces
|
|
41
45
|
private
|
42
46
|
|
43
47
|
def files_to_serve(path)
|
44
|
-
Dir["#{path}/build/**/*"].map { |file| file.sub("#{path}/build", '') }
|
48
|
+
Dir["#{config.path}/build/**/*"].map { |file| file.sub("#{config.path}/build", '') }
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
data/lib/pieces/version.rb
CHANGED
data/pieces.gemspec
CHANGED
@@ -28,4 +28,10 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'pry'
|
29
29
|
spec.add_development_dependency 'rake'
|
30
30
|
spec.add_development_dependency 'rspec'
|
31
|
+
spec.add_development_dependency 'rails'
|
32
|
+
spec.add_development_dependency 'rspec-rails'
|
33
|
+
spec.add_development_dependency 'capybara'
|
34
|
+
spec.add_development_dependency 'sass'
|
35
|
+
spec.add_development_dependency 'sqlite3'
|
36
|
+
spec.add_development_dependency 'pry-byebug'
|
31
37
|
end
|
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.
|
4
|
+
version: 0.5.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-08-
|
11
|
+
date: 2015-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -164,6 +164,90 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rails
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rspec-rails
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: capybara
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: sass
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: sqlite3
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: pry-byebug
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - ">="
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
167
251
|
description:
|
168
252
|
email:
|
169
253
|
- lukemorton.dev@gmail.com
|
@@ -204,6 +288,8 @@ files:
|
|
204
288
|
- examples/rails_app/Rakefile
|
205
289
|
- examples/rails_app/app/assets/images/.keep
|
206
290
|
- examples/rails_app/app/assets/javascripts/application.js
|
291
|
+
- examples/rails_app/app/assets/javascripts/components/article_summary.coffee
|
292
|
+
- examples/rails_app/app/assets/javascripts/pieces.js
|
207
293
|
- examples/rails_app/app/assets/stylesheets/application.css
|
208
294
|
- examples/rails_app/app/assets/stylesheets/components/article_summary.scss
|
209
295
|
- examples/rails_app/app/assets/stylesheets/components/branding.scss
|
@@ -256,14 +342,18 @@ files:
|
|
256
342
|
- examples/rails_app/public/favicon.ico
|
257
343
|
- examples/rails_app/public/robots.txt
|
258
344
|
- lib/pieces.rb
|
345
|
+
- lib/pieces/backtrace_formatter.rb
|
259
346
|
- lib/pieces/builder.rb
|
260
347
|
- lib/pieces/cli.rb
|
261
|
-
- lib/pieces/
|
348
|
+
- lib/pieces/config.rb
|
349
|
+
- lib/pieces/configurable.rb
|
262
350
|
- lib/pieces/generator.rb
|
263
351
|
- lib/pieces/listener.rb
|
352
|
+
- lib/pieces/publisher.rb
|
264
353
|
- lib/pieces/rails.rb
|
265
354
|
- lib/pieces/rails/install_generator.rb
|
266
355
|
- lib/pieces/rails/railtie.rb
|
356
|
+
- lib/pieces/route_compiler.rb
|
267
357
|
- lib/pieces/server.rb
|
268
358
|
- lib/pieces/tilt/mustache.rb
|
269
359
|
- lib/pieces/tilt_extension.rb
|