pyro 0.8.1 → 0.8.2

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: 466d3bf298063248a37e9cca1c9410f3df3af692
4
- data.tar.gz: 3b188ddb71727a2883d5f02ea40e3c4fbc8f9de8
3
+ metadata.gz: 6bd1bf4ed996354ed3062c91b4a02b715134ac06
4
+ data.tar.gz: b8b339877b19d8bbbd5f88bcb3ee6bee10703557
5
5
  SHA512:
6
- metadata.gz: 5867cb7ec1177eb5ead0fe4ab41d4934d7033bc4676d838daa2b15df86ec5a4090349ab19b5636cff5cadb4c90de4b5b8f033a6fe2f93f8a73bbae2c75e66bc4
7
- data.tar.gz: 09802df518d8d95a7940595962f4739fe0cc41335f60c9bb6cfb97563a0e8b2fec650b8470b3029cf2ee46d2b51da2aa163ee813aa19ea95dd4dfd9454792119
6
+ metadata.gz: 50a3a7a9826d8a712b9a66093a361e19c2794891d7463dcab2543139f78b7873e0d738d2e515b37d41db8cef969abd85b371da36160bd5efd5a073f1b6f9cb1c
7
+ data.tar.gz: 0380b829150a09f559f78c12f4225d7f398db8bb6ff1ccc6535b3b9d054a7c74f42931967153ef0fd6c5d94b91527c3083b4903db97251aebd0d0310424586ba
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  .bundle
4
4
  Gemfile.lock
5
5
  pkg/*
6
+ /coverage
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ gemfile:
2
+ - Gemfile
3
+ language: ruby
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
- > **DISCLAIMER**: A lot of this is still being developed.
2
-
3
- > Consider this readme a preview of code to come. (see: [Readme Driven Development](http://tom.preston-werner.com/2010/08/23/readme-driven-development.html))
4
-
5
- ---
6
-
7
1
  # Pyro
8
2
 
9
3
  > Build Ember.js apps with CoffeeScript and Sass... without all that damn configuration.
10
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/pyro.png)](http://badge.fury.io/rb/pyro)
6
+ [![Dependency Status](https://gemnasium.com/jarrodtaylor/pyro.png)](https://gemnasium.com/jarrodtaylor/pyro)
7
+ [![Code Climate](https://codeclimate.com/github/jarrodtaylor/pyro.png)](https://codeclimate.com/github/jarrodtaylor/pyro)
8
+ [![Build Status](https://travis-ci.org/jarrodtaylor/pyro.png?branch=master)](https://travis-ci.org/jarrodtaylor/pyro)
9
+ [![Coverage Status](https://coveralls.io/repos/jarrodtaylor/pyro/badge.png?branch=master)](https://coveralls.io/r/jarrodtaylor/pyro?branch=master)
10
+
11
+ ---
12
+
11
13
  Pyro is a Ruby gem for building Ember.js apps. Under the hood, it's a build script wrapped in a web server.
12
14
 
13
15
  ## tl;dr
@@ -75,7 +77,6 @@ Pyro uses file extensions to determine how to compile your and link to your code
75
77
  - CoffeeScript (.coffee)
76
78
  - JavaScript (.js)
77
79
  - Sass (.scss)
78
- - Less (.less)
79
80
  - CSS (.css)
80
81
  - Handlebars (.hbs, .handlebars, .x-handlebars)
81
82
 
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env rake
2
-
3
1
  require 'bundler/gem_tasks'
4
2
  require 'rake/testtask'
5
3
 
data/bin/pyro CHANGED
@@ -4,31 +4,34 @@ require 'thor'
4
4
  require 'pyro'
5
5
 
6
6
  class PyroCLI < Thor
7
-
7
+
8
8
  desc 'new NAME', 'Creats a new app'
9
9
  def new(name)
10
10
  FileUtils.cp_r("#{File.dirname(__FILE__)}/../template", name)
11
11
  end
12
12
 
13
- desc 'build', 'Builds the app for production'
14
- def build
15
- Pyro.build
13
+ desc 'build DIR', 'Builds an app for production'
14
+ def build(dir = '.')
15
+ Pyro.build('production', false, dir)
16
16
  end
17
17
 
18
- desc 'serve', 'Starts a Pyro app on localhost, --fast skips asset reloading'
18
+ desc 'serve DIR', 'Starts a Pyro app on localhost, --fast skips asset reloading'
19
19
  option :fast
20
- def serve
20
+ def serve(dir = '.')
21
21
  require 'pyro/server'
22
-
22
+
23
+ PyroServer.set :src_folder, dir
24
+ PyroServer.set :public_folder, "#{PyroServer.settings.src_folder}/builds/development"
25
+
23
26
  if options[:fast]
24
27
  PyroServer.set :fast, true
25
28
  else
26
29
  PyroServer.set :fast, false
27
30
  end
28
-
31
+
29
32
  PyroServer.run!
30
33
  end
31
-
34
+
32
35
  end
33
36
 
34
37
  PyroCLI.start(ARGV)
data/lib/pyro.rb CHANGED
@@ -1,33 +1,38 @@
1
1
  require 'fileutils'
2
- require 'pyro/assets/scripts'
3
- require 'pyro/assets/stylesheets'
4
- require 'pyro/assets/templates'
2
+ require 'pyro/assets'
5
3
 
6
4
  module Pyro
7
5
  include Pyro::Assets
8
-
9
- def self.build(target = 'production', fast = false)
10
- unless File.exists? './lib/index.erb'
6
+
7
+ def self.build(target = 'production', fast = false, working_dir = '.')
8
+ @timestamp = Time.now.strftime("%Y%m%d%H%M%S")
9
+ @working_dir = working_dir
10
+
11
+ unless File.exists? "#{@working_dir}/lib/index.erb"
11
12
  raise 'Can\'t find an index.erb file to build.'
12
13
  end
13
-
14
- $timestamp = Time.now.strftime("%Y%m%d%H%M%S")
15
-
14
+
16
15
  if target == 'development'
17
- $build_dir = './builds/development'
16
+ @build_dir = "#{@working_dir}/builds/development"
18
17
  else
19
- $build_dir = "./builds/production/#{$timestamp}"
18
+ @build_dir = "#{@working_dir}/builds/production/#{@timestamp}"
20
19
  end
21
-
22
- FileUtils.mkdir_p($build_dir)
23
-
20
+
21
+ FileUtils.mkdir_p(@build_dir)
22
+
24
23
  unless fast
25
- FileUtils.cp_r('./assets/.', $build_dir)
26
- FileUtils.cp_r('./vendor', $build_dir)
24
+ FileUtils.cp_r("#{@working_dir}/assets/.", @build_dir)
25
+ FileUtils.cp_r("#{@working_dir}/vendor", @build_dir)
26
+ end
27
+
28
+ File.open("#{@build_dir}/index.html", 'w+') do |index|
29
+ index.write(
30
+ ERB.new(File.read "#{@working_dir}/lib/index.erb").result(binding)
31
+ )
27
32
  end
28
33
 
29
- File.open("#{$build_dir}/index.html", 'w+') do |index|
30
- index.write( ERB.new(File.read './lib/index.erb').result(binding) )
34
+ if target == 'production'
35
+ compress(@build_dir)
31
36
  end
32
37
  end
33
38
  end
@@ -0,0 +1,131 @@
1
+ require 'fileutils'
2
+ require 'coffee-script'
3
+ require 'jsmin'
4
+ require 'sass'
5
+
6
+ module Pyro
7
+ module Assets
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ end
11
+
12
+ module ClassMethods
13
+
14
+ def script(*args)
15
+ tags = ''
16
+ find_files(args.first, 'js,coffee').each do |file|
17
+ tags << compile(file, 'js')
18
+ end
19
+ tags
20
+ end
21
+
22
+ def stylesheet(*args)
23
+ tags = ''
24
+ find_files(args.first, 'css,scss').each do |file|
25
+ tags << compile(file, 'css')
26
+ end
27
+ tags
28
+ end
29
+
30
+ def template(*args)
31
+ tags = ''
32
+ find_files(args.first, 'hbs,handlebars,x-handlebars').each do |file|
33
+ tags << "<script type='text/x-handlebars' data-template-name='#{parse_name(args.first, file)}'>\n"
34
+ tags << File.read(file)
35
+ tags << "\n</script>\n"
36
+ end
37
+ tags
38
+ end
39
+
40
+ private
41
+
42
+ def find_files(args, extensions)
43
+ files = []
44
+ if args[:src]
45
+ files << "#{@working_dir}/lib/#{args[:src]}"
46
+ elsif args[:dir]
47
+ Dir.glob("#{@working_dir}/lib/#{args[:dir]}/**/*.{#{extensions}}").each do |f|
48
+ files << f
49
+ end
50
+ end
51
+ files
52
+ end
53
+
54
+ def parse_path(path)
55
+ p = {}
56
+ p[:file_name] = path.split('/').last
57
+ p[:extension] = path.split('.').last
58
+ p[:name] = p[:file_name].sub(".#{p[:extension]}", '')
59
+ p[:path] = path.sub(p[:file_name], '')
60
+ p[:build_path] = p[:path].sub('./', "#{@build_dir}/")
61
+ p[:contents] = File.read(path)
62
+ p
63
+ end
64
+
65
+ def parse_name(args, file)
66
+ if args[:name]
67
+ name = args[:name]
68
+ elsif args[:src]
69
+ name = f.split('/').last.split('.').first
70
+ elsif args[:dir]
71
+ name = file.sub("#{@working_dir}/lib/#{args[:dir]}/", '').split('.').first
72
+ else
73
+ name = 'name-not-found'
74
+ end
75
+ name
76
+ end
77
+
78
+ def generate_file(path_attrs, extension)
79
+ FileUtils.mkdir_p(path_attrs[:build_path])
80
+ File.open("#{path_attrs[:build_path]}/#{path_attrs[:name]}.#{extension}", 'w+') do |f|
81
+ f.write(path_attrs[:contents])
82
+ end
83
+ end
84
+
85
+ def generate_link(path, extension)
86
+ path = path.sub(@working_dir, '')
87
+ case extension
88
+ when 'js'
89
+ "<script src='#{path}?#{@timestamp}' type='text/javascript'></script>"
90
+ when 'css'
91
+ "<link rel='stylesheet' href='#{path}?#{@timestamp}' type='text/css' />"
92
+ end
93
+ end
94
+
95
+ def compile(file, extension)
96
+ path_attrs = parse_path(file)
97
+
98
+ case path_attrs[:extension]
99
+ when 'coffee'
100
+ path_attrs[:contents] = CoffeeScript.compile(path_attrs[:contents])
101
+ when 'scss'
102
+ path_attrs[:contents] = Sass::Engine.new( path_attrs[:contents],
103
+ { style: :expanded,
104
+ syntax: :scss } ).render
105
+ end
106
+ generate_file(path_attrs, extension)
107
+
108
+ generate_link(file.gsub(path_attrs[:extension], extension), extension)
109
+ end
110
+
111
+ def compress(dir)
112
+ Dir.glob("#{dir}/**/*.js").each do |file|
113
+ contents = File.read(file)
114
+ File.open(file, 'w+') do |f|
115
+ f.write(JSMin.minify(contents).strip)
116
+ end
117
+ end
118
+
119
+ Dir.glob("#{dir}/**/*.css").each do |file|
120
+ contents = File.read(file)
121
+ File.open(file, 'w+') do |f|
122
+ f.write(Sass::Engine.new( contents, { style: :compressed,
123
+ syntax: :scss } ).render)
124
+ end
125
+
126
+ end
127
+ end
128
+
129
+ end
130
+ end
131
+ end
data/lib/pyro/server.rb CHANGED
@@ -4,20 +4,14 @@ require 'erb'
4
4
 
5
5
  class PyroServer < Sinatra::Base
6
6
  include Pyro
7
-
7
+
8
8
  set :port, 5678
9
9
  set :public_folder, './builds/development'
10
10
  set :fast_build, false
11
-
12
- #helpers do
13
- # define_method(:script) { |*args| Pyro.script public_folder, args }
14
- # define_method(:stylesheet) { |*args| Pyro.stylesheet args }
15
- # define_method(:template) { |*args| Pyro.template args }
16
- #end
17
-
11
+
18
12
  get '/?' do
19
- Pyro.build('development', settings.fast_build)
13
+ Pyro.build('development', settings.fast_build, settings.src_folder)
20
14
  settings.fast_build = settings.fast
21
- File.read('./builds/development/index.html')
15
+ File.read("#{settings.src_folder}/builds/development/index.html")
22
16
  end
23
17
  end
data/pyro.gemspec CHANGED
@@ -4,11 +4,13 @@ $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 = "0.8.1"
7
+ gem.version = "0.8.2"
8
8
  gem.authors = "Jarrod Taylor"
9
9
  gem.email = "jarrodtaylor@icloud.com"
10
- gem.summary = "Build Ember.js apps with CoffeeScript and Sass... without all that damn configuration."
11
10
  gem.homepage = "https://github.com/jarrodtaylor/pyro"
11
+ gem .license = 'MIT'
12
+ gem.summary = "Build Ember.js apps with CoffeeScript and Sass...
13
+ without all that damn configuration."
12
14
 
13
15
  gem.files = `git ls-files`.split($/)
14
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -17,9 +19,11 @@ Gem::Specification.new do |gem|
17
19
 
18
20
  gem.add_dependency 'coffee-script'
19
21
  gem.add_dependency 'jsmin'
20
- gem.add_dependency 'less'
22
+ gem.add_dependency 'minitest'
21
23
  gem.add_dependency 'rake'
22
24
  gem.add_dependency 'sass'
23
25
  gem.add_dependency 'sinatra'
24
26
  gem.add_dependency 'thor'
27
+
28
+ gem.add_development_dependency 'coveralls'
25
29
  end
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8">
5
5
  <title>Ember Starter Kit</title>
6
6
  <%= stylesheet src: 'stylesheets/normalize.css' %>
7
- <%= stylesheet src: 'stylesheets/style.css' %>
7
+ <%= stylesheet src: 'stylesheets/style.scss' %>
8
8
  </head>
9
9
  <body>
10
10
  <%= template dir: 'templates' %>
@@ -0,0 +1,7 @@
1
+ /* Put your SCSS here */
2
+
3
+ $margin: 20px;
4
+
5
+ html, body {
6
+ margin: 20px;
7
+ }
@@ -0,0 +1,8 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require './lib/pyro.rb'
5
+
6
+ require 'minitest'
7
+ require 'minitest/autorun'
8
+ require 'minitest/pride'
data/test/test_pyro.rb ADDED
@@ -0,0 +1,18 @@
1
+ class TestPyro < Minitest::Test
2
+
3
+ def test_build
4
+ Pyro.build('development', false, './template')
5
+ assert Dir.exists?('./template/builds/development')
6
+
7
+ Pyro.build('production', false, './template')
8
+ assert Dir.exists?('./template/builds/production')
9
+
10
+ FileUtils.rm_rf('./template/builds')
11
+ refute Dir.exists?('./template/builds')
12
+
13
+ assert_raises RuntimeError do
14
+ Pyro.build
15
+ end
16
+ end
17
+
18
+ end
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: 0.8.1
4
+ version: 0.8.2
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-08-16 00:00:00.000000000 Z
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-script
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: less
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '>='
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description:
112
126
  email: jarrodtaylor@icloud.com
113
127
  executables:
@@ -116,30 +130,32 @@ extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
118
132
  - .gitignore
133
+ - .travis.yml
119
134
  - Gemfile
120
135
  - LICENSE
121
136
  - README.md
122
137
  - Rakefile
123
138
  - bin/pyro
124
139
  - lib/pyro.rb
125
- - lib/pyro/assets/scripts.rb
126
- - lib/pyro/assets/stylesheets.rb
127
- - lib/pyro/assets/templates.rb
140
+ - lib/pyro/assets.rb
128
141
  - lib/pyro/server.rb
129
142
  - pyro.gemspec
130
143
  - template/assets/img/favicon.ico
131
144
  - template/lib/app.coffee
132
145
  - template/lib/index.erb
133
146
  - template/lib/stylesheets/normalize.css
134
- - template/lib/stylesheets/style.css
147
+ - template/lib/stylesheets/style.scss
135
148
  - template/lib/templates/application.hbs
136
149
  - template/lib/templates/index.hbs
137
150
  - template/vendor/ember/ember-1.0.0-rc.7.js
138
151
  - template/vendor/ember/ember-data-0.13.js
139
152
  - template/vendor/handlebars/handlebars-1.0.0.js
140
153
  - template/vendor/jquery/jquery-1.9.1.js
154
+ - test/test_helper.rb
155
+ - test/test_pyro.rb
141
156
  homepage: https://github.com/jarrodtaylor/pyro
142
- licenses: []
157
+ licenses:
158
+ - MIT
143
159
  metadata: {}
144
160
  post_install_message:
145
161
  rdoc_options: []
@@ -157,9 +173,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
173
  version: '0'
158
174
  requirements: []
159
175
  rubyforge_project:
160
- rubygems_version: 2.0.0
176
+ rubygems_version: 2.0.3
161
177
  signing_key:
162
178
  specification_version: 4
163
179
  summary: Build Ember.js apps with CoffeeScript and Sass... without all that damn configuration.
164
- test_files: []
165
- has_rdoc:
180
+ test_files:
181
+ - test/test_helper.rb
182
+ - test/test_pyro.rb
@@ -1,47 +0,0 @@
1
- require 'fileutils'
2
- require 'coffee-script'
3
-
4
- module Pyro
5
- module Assets
6
- def self.included(base)
7
- base.extend(ClassMethods)
8
- end
9
-
10
- module ClassMethods
11
-
12
- def script *args
13
- args = args.first
14
-
15
- scripts = []
16
- scripts << "./lib/#{args[:src]}" if args[:src]
17
- if args[:dir]
18
- Dir.glob("./lib/#{args[:dir]}/**/*.{js,coffee}").each do |f|
19
- scripts << f
20
- end
21
- end
22
-
23
- tags = ''
24
- scripts.each do |s|
25
- file_name = s.split('/').last
26
- extension = s.split('.').last
27
- name = file_name.sub(".#{extension}", '')
28
- path = s.sub(file_name, '')
29
- build_path = path.sub('./', "#{$build_dir}/")
30
- FileUtils.mkdir_p(build_path)
31
-
32
- contents = File.read(s)
33
- contents = CoffeeScript.compile(contents) if extension == 'coffee'
34
-
35
- File.open("#{build_path}/#{name}.js", 'w+') do |f|
36
- f.write(contents)
37
- end
38
-
39
- tags << "<script src='#{s.gsub(extension, 'js')}?#{$timestamp}' type='text/javascript'></script>"
40
- end
41
-
42
- tags
43
- end
44
-
45
- end
46
- end
47
- end
@@ -1,53 +0,0 @@
1
- require 'fileutils'
2
- require 'less'
3
- require 'sass'
4
-
5
- module Pyro
6
- module Assets
7
- def self.included(base)
8
- base.extend(ClassMethods)
9
- end
10
-
11
- module ClassMethods
12
-
13
- def stylesheet *args
14
- args = args.first
15
-
16
- stylesheets = []
17
- stylesheets << "./lib/#{args[:src]}" if args[:src]
18
- if args[:dir]
19
- Dir.glob("./lib/#{args[:dir]}/**/*.{css,scss,less}").each do |f|
20
- stylesheets << f
21
- end
22
- end
23
-
24
- tags = ''
25
- stylesheets.each do |s|
26
- file_name = s.split('/').last
27
- extension = s.split('.').last
28
- name = file_name.sub(".#{extension}", '')
29
- path = s.sub(file_name, '')
30
- build_path = path.sub('./', "#{$build_dir}/")
31
- FileUtils.mkdir_p(build_path)
32
-
33
- contents = File.read(s)
34
- case extension
35
- when 'scss'
36
- contents = Sass::Engine.for_file(s, { style: :expanded }).render
37
- when 'less'
38
- contents = Less::Parser.new.parse(contents).to_css
39
- end
40
-
41
- File.open("#{build_path}/#{name}.css", 'w+') do |f|
42
- f.write(contents)
43
- end
44
-
45
- tags << "<link rel='stylesheet' href='#{s.gsub(extension, 'css')}?#{$timestamp}' type='text/css' />"
46
- end
47
-
48
- tags
49
- end
50
-
51
- end
52
- end
53
- end
@@ -1,46 +0,0 @@
1
- require 'fileutils'
2
-
3
- module Pyro
4
- module Assets
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- end
8
-
9
- module ClassMethods
10
-
11
- def template *args
12
- args = args.first
13
-
14
- templates = []
15
- templates << "./lib/#{args[:src]}" if args[:src]
16
- if args[:dir]
17
- Dir.glob("./lib/#{args[:dir]}/**/*.{hbs, handlebars,x-handlebars}").each do |f|
18
- templates << f
19
- end
20
- end
21
-
22
- tags = ''
23
- templates.each do |t|
24
- contents = File.read t
25
-
26
- if args[:name]
27
- name = args[:name]
28
- elsif args[:src]
29
- name = t.split('/').last.split('.').first
30
- elsif args[:dir]
31
- name = t.sub("./lib/#{args[:dir]}/", '').split('.').first
32
- else
33
- name = 'name-not-found'
34
- end
35
-
36
- tags << "\n<script type='text/x-handlebars' data-template-name='#{name}'>\n"
37
- tags << contents
38
- tags << "\n</script>\n"
39
- end
40
-
41
- tags
42
- end
43
-
44
- end
45
- end
46
- end
@@ -1,4 +0,0 @@
1
- /* Put your CSS here */
2
- html, body {
3
- margin: 20px;
4
- }