sinatra_asset_packager 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,6 +4,8 @@ Opinionated asset packaging for Sinatra done well.
4
4
 
5
5
  Uses Sprockets, Uglifier, and YUI Compressor under the hood.
6
6
 
7
+ Make all your (css|scss|sass|less) and (js|coffee) files only end with a single extension. I.E. .coffee instead of .js.coffee. And .sass, instead of .css.sass. This is for a reason. I find Rails' approach of .js.coffee redundant and less readable.
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -35,6 +37,38 @@ You also get the following task with it.
35
37
 
36
38
  If you are using heroku this will precompile your assets on deploy.
37
39
 
40
+ ## Other Options
41
+
42
+ Use the javascript_include_tag helper if you want to run multiple js files in development vs compiling all to one js file.
43
+
44
+ First, add the helpers to your application:
45
+
46
+ class Application < Sinatra::Base
47
+ helpers SinatraAssetPackager::Helpers
48
+
49
+ get "/" do
50
+ erb :index
51
+ end
52
+ end
53
+
54
+ Second, in your index.erb file place the following:
55
+
56
+ <!DOCTYPE html>
57
+ <html>
58
+ <head>
59
+ <title>YourApp</title>
60
+ <link href="/assets/application.css" media="all" rel="stylesheet" type="text/css" />
61
+ <%= javascript_include_tag :application %>
62
+ </head>
63
+ <body>
64
+ ...
65
+ </body>
66
+ </html>
67
+
68
+ Now the output will be multiple js files (similar to Rails Asset Pipeline setup) in development, but will be compiled to one in production and staging environments. Furthermore, if you want to use the helper and still compile do the following:
69
+
70
+ <%= javascript_include_tag :application, compile: true %>
71
+
38
72
  ## Contributing
39
73
 
40
74
  1. Fork it
@@ -0,0 +1,18 @@
1
+ module SinatraAssetPackager
2
+ module Helpers
3
+ def javascript_include_tag(source, options={})
4
+ if !!options[:compress] || ["production", "staging"].include?(ENV["RACK_ENV"])
5
+ "<script src='/assets/#{source}.js' type='text/javascript'></script>"
6
+ else
7
+ javascript = SinatraAssetPackager.environment["#{source}.js"]
8
+ javascript.dependencies.map do |script|
9
+ leading_replace = [Dir.pwd, "app", "assets", "javascripts/"].join("/")
10
+ ending_replace = /\.js|\.coffee$/
11
+ relative_path = script.pathname.to_s.gsub(leading_replace, "").gsub(ending_replace, "")
12
+
13
+ "<script src='/assets/#{relative_path}.js' type='text/javascript'></script>"
14
+ end.flatten.uniq.join("\n")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module SinatraAssetPackager
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -4,6 +4,7 @@ require "uglifier"
4
4
  require "yui/compressor"
5
5
  require "sinatra/base"
6
6
  require "sinatra_asset_packager/version"
7
+ require "sinatra_asset_packager/helpers"
7
8
  require "sinatra_asset_packager/routes"
8
9
  require "sinatra_asset_packager/rake"
9
10
 
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SinatraAssetPackager do
4
- it { SinatraAssetPackager::VERSION.should eq "0.0.4" }
4
+ it { SinatraAssetPackager::VERSION.should eq "0.0.5" }
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_asset_packager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-22 00:00:00.000000000 Z
12
+ date: 2013-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -153,6 +153,7 @@ files:
153
153
  - README.md
154
154
  - Rakefile
155
155
  - lib/sinatra_asset_packager.rb
156
+ - lib/sinatra_asset_packager/helpers.rb
156
157
  - lib/sinatra_asset_packager/rake.rb
157
158
  - lib/sinatra_asset_packager/routes.rb
158
159
  - lib/sinatra_asset_packager/version.rb
@@ -175,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
176
  version: '0'
176
177
  segments:
177
178
  - 0
178
- hash: 813428790698914983
179
+ hash: -1912420992989165148
179
180
  required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  none: false
181
182
  requirements:
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
185
  version: '0'
185
186
  segments:
186
187
  - 0
187
- hash: 813428790698914983
188
+ hash: -1912420992989165148
188
189
  requirements: []
189
190
  rubyforge_project:
190
191
  rubygems_version: 1.8.23