pyro 1.0.0.rc1 → 1.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pyro +57 -2
- data/lib/pyro.rb +17 -0
- data/lib/pyro/asset.rb +93 -3
- data/lib/pyro/assets.rb +59 -6
- data/lib/pyro/server.rb +10 -4
- data/pyro.gemspec +1 -1
- data/templates/app/index.erb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3605f85bb1db89f79e9093f4ff9eddd161adf9a8
|
4
|
+
data.tar.gz: 7a1fcbfa600aa8236315db0370fef4979d7877d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf23270974d0d3bcc194db597cfc33d267b90d6e30ef743b3e5e0f3bac0663f0eb73e85bafc2b2ee55506b2db9d8ffdbf84c661dcb2959b1416df550b815acc4
|
7
|
+
data.tar.gz: f578bf58b1a9af2217ec9c120fea1cb7b3b3e3b8a113f7e0ac8ffe40d086d9d977a963512bbf79635259bdb95c3d9957350cfa84c7eb197b2a72612eef2170c2
|
data/bin/pyro
CHANGED
@@ -3,22 +3,59 @@
|
|
3
3
|
require 'thor'
|
4
4
|
require 'pyro'
|
5
5
|
|
6
|
+
# Public: CLI commands for Pyro.
|
7
|
+
#
|
8
|
+
# Examples
|
9
|
+
#
|
10
|
+
# ~/Projects $ pyro new MyApp
|
6
11
|
class PyroCLI < Thor
|
7
12
|
|
13
|
+
# Public: Create a new Pyro app.
|
14
|
+
#
|
15
|
+
# name - The name of the new app.
|
16
|
+
#
|
17
|
+
# Examples
|
18
|
+
#
|
19
|
+
# ~/Projects $ pyro new MyApp
|
20
|
+
#
|
21
|
+
# Generates a new app into /MyApp.
|
8
22
|
desc 'new NAME', 'Creats a new app'
|
9
23
|
def new(name)
|
10
24
|
FileUtils.cp_r("#{File.dirname(__FILE__)}/../templates/app", name)
|
11
25
|
end
|
12
26
|
|
27
|
+
# Public: Create a new build of a Pyro app for production.
|
28
|
+
#
|
29
|
+
# * Production builds use prod_src/prod_dir, skip tests, and are minified.
|
30
|
+
#
|
31
|
+
# dir - The directory of the app to burn. Defaults to the current directory.
|
32
|
+
#
|
33
|
+
# Examples
|
34
|
+
#
|
35
|
+
# ~/Projects/MyApp $ pyro burn
|
36
|
+
# ~/Projects $ pyro burn MyApp # Burns the MyApp folder.
|
37
|
+
#
|
38
|
+
# Generates a production build of the app into /pkg/<timestamp>.
|
13
39
|
desc 'burn DIR', 'Builds an app for production'
|
14
40
|
def burn(dir = '.')
|
15
41
|
Pyro.burn('production', false, dir)
|
16
42
|
end
|
17
43
|
|
44
|
+
# Public: Create a development build in /tmp and runs it on localhost:7976.
|
45
|
+
#
|
46
|
+
# * /tmp gets rebuilt on each refresh.
|
47
|
+
#
|
48
|
+
# --fast - Doesn't rebuild /assets.
|
49
|
+
# --test - Builds with the test helpers.
|
50
|
+
#
|
51
|
+
# Examples
|
52
|
+
#
|
53
|
+
# ~/Projects/MyApp $ pyro serve
|
54
|
+
#
|
55
|
+
# Runs the development build on localhost:7976.
|
18
56
|
desc 'serve', 'Starts a Pyro app on localhost,
|
19
57
|
--fast skips asset reloading,
|
20
58
|
--test includes tests'
|
21
|
-
|
22
59
|
option :fast
|
23
60
|
option :test
|
24
61
|
def serve
|
@@ -35,6 +72,19 @@ class PyroCLI < Thor
|
|
35
72
|
PyroServer.run!
|
36
73
|
end
|
37
74
|
|
75
|
+
# Public: Run a production build on localhost:7976.
|
76
|
+
#
|
77
|
+
# build - The name (timestamp) of the build to run, from /pkg.
|
78
|
+
#
|
79
|
+
# * If no build is specified, the latest is used.
|
80
|
+
# * If no build exists, a new one is generated.
|
81
|
+
#
|
82
|
+
# Examples
|
83
|
+
#
|
84
|
+
# ~/Projects/MyApp $ pyro stage
|
85
|
+
# ~/Projects/MyApp $ pyro stage <timestamp>
|
86
|
+
#
|
87
|
+
# Runs the production build on localhost:7976.
|
38
88
|
desc 'stage BUILD', 'Stages a Pyro build on localhost'
|
39
89
|
def stage(build_num = false)
|
40
90
|
if build_num
|
@@ -45,7 +95,7 @@ class PyroCLI < Thor
|
|
45
95
|
end
|
46
96
|
|
47
97
|
unless Dir.exists? build_dir
|
48
|
-
puts "That build doesn't exist.
|
98
|
+
puts "That build doesn't exist. Run 'pyro burn' to create a build."
|
49
99
|
exit
|
50
100
|
end
|
51
101
|
|
@@ -57,4 +107,9 @@ class PyroCLI < Thor
|
|
57
107
|
|
58
108
|
end
|
59
109
|
|
110
|
+
# Public: Start the PyroCLI.
|
111
|
+
#
|
112
|
+
# Examples
|
113
|
+
#
|
114
|
+
# ~ $ pyro
|
60
115
|
PyroCLI.start(ARGV)
|
data/lib/pyro.rb
CHANGED
@@ -1,9 +1,26 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'pyro/assets'
|
3
3
|
|
4
|
+
# Public: Main script for running Pyro.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# Pyro.burn('development', true)
|
4
9
|
module Pyro
|
5
10
|
include Pyro::Assets
|
6
11
|
|
12
|
+
# Public: Burn a build of an app.
|
13
|
+
#
|
14
|
+
# target - 'development' or 'production' determines compression
|
15
|
+
# and output directory.
|
16
|
+
# fast - Boolean to run the server faster (skips rebuilding resources).
|
17
|
+
# working_dir - Path to the app.
|
18
|
+
#
|
19
|
+
# Examples
|
20
|
+
#
|
21
|
+
# Pyro.burn('development', true)
|
22
|
+
#
|
23
|
+
# Generates a built app.
|
7
24
|
def self.burn(target = 'production', fast = false, working_dir = '.')
|
8
25
|
@target = target
|
9
26
|
@timestamp = Time.now.strftime "%Y%m%d%H%M%S"
|
data/lib/pyro/asset.rb
CHANGED
@@ -3,42 +3,95 @@ require 'coffee-script'
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'sass'
|
5
5
|
|
6
|
+
# Public: Define an Asset.
|
7
|
+
#
|
8
|
+
# Examples
|
9
|
+
#
|
10
|
+
# Asset.new(file: "#{@working_dir}/#{args[:src]}",
|
11
|
+
# build_dir: @build_dir,
|
12
|
+
# working_dir: @working_dir,
|
13
|
+
# helper_args: args)
|
6
14
|
module Pyro
|
7
15
|
class Asset
|
8
16
|
attr_accessor :file, :build_dir, :working_dir, :helper_args
|
9
17
|
|
18
|
+
# Public: Set args to attrs on new().
|
19
|
+
#
|
20
|
+
# Examples
|
21
|
+
#
|
22
|
+
# Asset.new(file: "#{@working_dir}/#{args[:src]}",
|
23
|
+
# build_dir: @build_dir,
|
24
|
+
# working_dir: @working_dir,
|
25
|
+
# helper_args: args)
|
26
|
+
#
|
27
|
+
# Returns an Asset instance.
|
10
28
|
def initialize(args)
|
11
29
|
args.each { |k, v| instance_variable_set("@#{k}", v) }
|
12
30
|
end
|
13
31
|
|
32
|
+
# Public: Map File methods to an Asset.
|
33
|
+
#
|
34
|
+
# * Maybe Asset should inheret from File?
|
35
|
+
#
|
36
|
+
# Examples
|
37
|
+
#
|
38
|
+
# @asset.mtime
|
39
|
+
#
|
40
|
+
# * See the File class for more info.
|
14
41
|
def mtime
|
15
42
|
File.mtime file
|
16
43
|
end
|
17
|
-
|
18
44
|
def basename
|
19
45
|
File.basename file
|
20
46
|
end
|
21
|
-
|
22
47
|
def dirname
|
23
48
|
File.dirname file
|
24
49
|
end
|
25
|
-
|
26
50
|
def extname
|
27
51
|
File.extname file
|
28
52
|
end
|
29
53
|
|
54
|
+
# Public: Strip the extension from the basename.
|
55
|
+
#
|
56
|
+
# Examples
|
57
|
+
#
|
58
|
+
# @asset.name
|
59
|
+
#
|
60
|
+
# Retunrs a String of the basename without the extension.
|
61
|
+
# ('my_file.rb' -> 'myfile')
|
30
62
|
def name
|
31
63
|
basename.sub(extname, '')
|
32
64
|
end
|
33
65
|
|
66
|
+
# Public: Format the mtime as a timestamp String.
|
67
|
+
#
|
68
|
+
# Examples
|
69
|
+
#
|
70
|
+
# @asset.timestamp
|
71
|
+
#
|
72
|
+
# Returns a String.
|
34
73
|
def timestamp
|
35
74
|
mtime.strftime "%Y%m%d%H%M%S"
|
36
75
|
end
|
37
76
|
|
77
|
+
# Public: Find the relative target path of an Asset.
|
78
|
+
#
|
79
|
+
# Examples
|
80
|
+
#
|
81
|
+
# @asset.relative_dir
|
82
|
+
#
|
83
|
+
# Returns a path as a String.
|
38
84
|
def relative_dir
|
39
85
|
dirname.sub("#{working_dir}/", '')
|
40
86
|
end
|
41
87
|
|
88
|
+
# Public: Find the relative target file path of an Asset.
|
89
|
+
#
|
90
|
+
# Examples
|
91
|
+
#
|
92
|
+
# @asset.relative_file
|
93
|
+
#
|
94
|
+
# Returns a filepath as a String.
|
42
95
|
def relative_file
|
43
96
|
if helper_args[:target]
|
44
97
|
helper_args[:target]
|
@@ -47,6 +100,13 @@ module Pyro
|
|
47
100
|
end
|
48
101
|
end
|
49
102
|
|
103
|
+
# Public: Determine the target extension of an Asset.
|
104
|
+
#
|
105
|
+
# Examples
|
106
|
+
#
|
107
|
+
# @asset.compiled_ext
|
108
|
+
#
|
109
|
+
# Returns a String.
|
50
110
|
def compiled_ext
|
51
111
|
case extname
|
52
112
|
when '.coffee', '.hbs', '.handlebars'
|
@@ -58,6 +118,13 @@ module Pyro
|
|
58
118
|
end
|
59
119
|
end
|
60
120
|
|
121
|
+
# Public: Compile the contents of an Asset.
|
122
|
+
#
|
123
|
+
# Examples
|
124
|
+
#
|
125
|
+
# @asset.contents
|
126
|
+
#
|
127
|
+
# Returns the compiled contents.
|
61
128
|
def contents
|
62
129
|
contents = File.read file
|
63
130
|
case extname
|
@@ -72,6 +139,15 @@ module Pyro
|
|
72
139
|
contents
|
73
140
|
end
|
74
141
|
|
142
|
+
# Public: Find the name to use for a Handlebars template.
|
143
|
+
#
|
144
|
+
# * Use the name: arg in the template() helper to override the default.
|
145
|
+
#
|
146
|
+
# Examples
|
147
|
+
#
|
148
|
+
# @asset.template_name
|
149
|
+
#
|
150
|
+
# Returns the relative template path and filename unless told otherwise.
|
75
151
|
def template_name
|
76
152
|
if helper_args[:name]
|
77
153
|
helper_args[:name]
|
@@ -84,11 +160,25 @@ module Pyro
|
|
84
160
|
end
|
85
161
|
end
|
86
162
|
|
163
|
+
# Public: Generate a compiled Asset.
|
164
|
+
#
|
165
|
+
# Examples
|
166
|
+
#
|
167
|
+
# @asset.generate_file
|
168
|
+
#
|
169
|
+
# Generates a compiled Asset file into a target file.
|
87
170
|
def generate_file
|
88
171
|
FileUtils.mkdir_p "#{build_dir}/#{relative_dir}"
|
89
172
|
File.open("#{build_dir}/#{relative_file}", 'a+') { |f| f.write contents }
|
90
173
|
end
|
91
174
|
|
175
|
+
# Public: Generate link to a generated Asset.
|
176
|
+
#
|
177
|
+
# Examples
|
178
|
+
#
|
179
|
+
# @asset.generate_link
|
180
|
+
#
|
181
|
+
# Retunrs a <script> or <link> tag.
|
92
182
|
def generate_link
|
93
183
|
case compiled_ext
|
94
184
|
when '.js'
|
data/lib/pyro/assets.rb
CHANGED
@@ -3,6 +3,11 @@ require 'jsmin'
|
|
3
3
|
require 'sass'
|
4
4
|
require 'pyro/asset'
|
5
5
|
|
6
|
+
# Public: Manage Assets.
|
7
|
+
#
|
8
|
+
# Examples
|
9
|
+
#
|
10
|
+
# Pyro::Assets.compress('./tmp/public')
|
6
11
|
module Pyro
|
7
12
|
module Assets
|
8
13
|
def self.included(base)
|
@@ -11,16 +16,45 @@ module Pyro
|
|
11
16
|
|
12
17
|
module ClassMethods
|
13
18
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
# Public: Helpers for index.erb.
|
20
|
+
#
|
21
|
+
# src - Path to source file.
|
22
|
+
# dir - Path to directory of source files.
|
23
|
+
# prod_src - Path to production version of source file.
|
24
|
+
# prod_dir - Path to directory of production versions of source files.
|
25
|
+
# target - Path to output file (defaults to build path + source path).
|
26
|
+
# name - String to name a Handlebars template.
|
27
|
+
#
|
28
|
+
# Examples
|
29
|
+
#
|
30
|
+
# <%= script src: '/lib/app.coffee' %>
|
31
|
+
#
|
32
|
+
# Returns an asset tag (<script> or <link>).
|
33
|
+
def script(*args)
|
34
|
+
build(args.first, 'js, coffee')
|
35
|
+
end
|
36
|
+
def stylesheet(*args)
|
37
|
+
build(args.first, 'css, scss')
|
38
|
+
end
|
39
|
+
def template(*args)
|
40
|
+
build(args.first, 'hbs, handlebars')
|
41
|
+
end
|
18
42
|
def test(*args)
|
19
43
|
build(args.first, 'js, coffee, css, scss') if @target == 'test'
|
20
44
|
end
|
21
45
|
|
22
46
|
private
|
23
47
|
|
48
|
+
# Private: Find and compile assets.
|
49
|
+
#
|
50
|
+
# args - Args.first from the helpers.
|
51
|
+
# src_ext - The source file extensions filter by.
|
52
|
+
#
|
53
|
+
# Examples
|
54
|
+
#
|
55
|
+
# build(args.first, 'css, scss')
|
56
|
+
#
|
57
|
+
# Returns an asset tag (<script> or <link>).
|
24
58
|
def build(args, src_ext)
|
25
59
|
tags = ''
|
26
60
|
find_assets(args, src_ext).each do |asset|
|
@@ -34,6 +68,16 @@ module Pyro
|
|
34
68
|
tags
|
35
69
|
end
|
36
70
|
|
71
|
+
# Private: Find assets.
|
72
|
+
#
|
73
|
+
# args - Args from build().
|
74
|
+
# exts - The source file extensions filter by.
|
75
|
+
#
|
76
|
+
# Examples
|
77
|
+
#
|
78
|
+
# find_assets(args, src_ext)
|
79
|
+
#
|
80
|
+
# Returns an Array of Asset instances.
|
37
81
|
def find_assets(args, exts)
|
38
82
|
if @target == 'production'
|
39
83
|
args[:src] = args[:prod_src] if args[:prod_src]
|
@@ -47,8 +91,8 @@ module Pyro
|
|
47
91
|
working_dir: @working_dir,
|
48
92
|
helper_args: args)
|
49
93
|
elsif args[:dir]
|
50
|
-
Dir.glob("#{@working_dir}/#{args[:dir]}/**/*.{#{exts}}").each do |
|
51
|
-
assets << Asset.new(file:
|
94
|
+
Dir.glob("#{@working_dir}/#{args[:dir]}/**/*.{#{exts}}").each do |f|
|
95
|
+
assets << Asset.new(file: f,
|
52
96
|
build_dir: @build_dir,
|
53
97
|
working_dir: @working_dir,
|
54
98
|
helper_args: args)
|
@@ -57,6 +101,15 @@ module Pyro
|
|
57
101
|
assets
|
58
102
|
end
|
59
103
|
|
104
|
+
# Private: Compress all assets in a directory.
|
105
|
+
#
|
106
|
+
# dir - Path of directory to compress.
|
107
|
+
#
|
108
|
+
# Examples
|
109
|
+
#
|
110
|
+
# Pyro::Assets.compress('./tmp/lib')
|
111
|
+
#
|
112
|
+
# Asset files are overwritten with their own compressed contents.
|
60
113
|
def compress(dir)
|
61
114
|
Dir.glob("#{dir}/**/*.js").each do |file|
|
62
115
|
contents = File.read(file)
|
data/lib/pyro/server.rb
CHANGED
@@ -2,15 +2,21 @@ require 'pyro'
|
|
2
2
|
require 'sinatra/base'
|
3
3
|
require 'erb'
|
4
4
|
|
5
|
+
# Public: Run a Pyro app on a Sinatra server.
|
6
|
+
#
|
7
|
+
# Examples
|
8
|
+
#
|
9
|
+
# ~/MyApp $ pyro serve
|
5
10
|
class PyroServer < Sinatra::Base
|
6
11
|
include Pyro
|
7
12
|
|
8
|
-
set :fast_build, false
|
13
|
+
set :fast_build, false # true to skip reloading resources.
|
9
14
|
set :port, 7976
|
10
|
-
set :public_folder, './tmp'
|
11
|
-
set :staging, false
|
12
|
-
set :target, 'development'
|
15
|
+
set :public_folder, './tmp' # Override for staging builds.
|
16
|
+
set :staging, false # true to skip hot-rebuilding.
|
17
|
+
set :target, 'development' # 'test' to use test helpers.
|
13
18
|
|
19
|
+
# Public: Burn an app and response with the built index.html.
|
14
20
|
get '/?' do
|
15
21
|
unless settings.staging
|
16
22
|
Pyro.burn(settings.target, settings.fast_build)
|
data/pyro.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "pyro"
|
7
|
-
gem.version = "1.0.0.
|
7
|
+
gem.version = "1.0.0.rc2"
|
8
8
|
gem.authors = "Jarrod Taylor"
|
9
9
|
gem.email = "jarrodtaylor@icloud.com"
|
10
10
|
gem.homepage = "https://github.com/jarrodtaylor/pyro"
|
data/templates/app/index.erb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pyro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarrod Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: barber
|