kelredd-sprockets-sinatra 0.2.0
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.
- data/README.rdoc +52 -0
- data/Rakefile +40 -0
- data/lib/sprockets_sinatra.rb +2 -0
- data/lib/sprockets_sinatra/base.rb +38 -0
- data/lib/sprockets_sinatra/version.rb +13 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/sprockets_sinatra_test.rb +13 -0
- metadata +62 -0
data/README.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
= SprocketsSinatra
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
This gem extends a sinatra app with helpers for using sprockets. It was inspired by and is an adaptation of sprockets-rails, http://github.com/sstephenson/sprockets-rails/tree/master
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
sudo gem install sprockets-sinatra --source=http://gems.github.com
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
(in main app file)
|
14
|
+
require 'sprockets_sinatra'
|
15
|
+
|
16
|
+
(create a file config/sprocket.yml, and put something like this in it)
|
17
|
+
:file_name: app
|
18
|
+
:asset_root: public
|
19
|
+
:load_path:
|
20
|
+
- javascripts
|
21
|
+
- vendor/sprockets/*/src
|
22
|
+
- vendor/plugins/*/javascripts
|
23
|
+
:source_files:
|
24
|
+
- javascripts/application.js
|
25
|
+
|
26
|
+
(build out any files directories needed based on how you configured above)
|
27
|
+
(it's based on sprockets-rails, so look there for more reference)
|
28
|
+
|
29
|
+
== License
|
30
|
+
|
31
|
+
Copyright (c) 2009 Kelly Redding
|
32
|
+
|
33
|
+
Permission is hereby granted, free of charge, to any person
|
34
|
+
obtaining a copy of this software and associated documentation
|
35
|
+
files (the "Software"), to deal in the Software without
|
36
|
+
restriction, including without limitation the rights to use,
|
37
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
38
|
+
copies of the Software, and to permit persons to whom the
|
39
|
+
Software is furnished to do so, subject to the following
|
40
|
+
conditions:
|
41
|
+
|
42
|
+
The above copyright notice and this permission notice shall be
|
43
|
+
included in all copies or substantial portions of the Software.
|
44
|
+
|
45
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
46
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
47
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
48
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
49
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
50
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
51
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
52
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
require 'lib/sprockets_sinatra/version'
|
6
|
+
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
spec = Gem::Specification.new do |s|
|
10
|
+
s.name = 'sprockets-sinatra'
|
11
|
+
s.version = SprocketsSinatra::Version.to_s
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.extra_rdoc_files = %w(README.rdoc)
|
14
|
+
s.rdoc_options = %w(--main README.rdoc)
|
15
|
+
s.summary = "This gem extends a sinatra app with helpers for using sprockets."
|
16
|
+
s.author = 'Kelredd'
|
17
|
+
s.email = 'kelredd@example.com'
|
18
|
+
s.homepage = 'http://kelredd.com'
|
19
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
|
20
|
+
# s.executables = ['sprockets-sinatra']
|
21
|
+
|
22
|
+
# s.add_dependency('gem_name', '~> 0.0.1')
|
23
|
+
end
|
24
|
+
|
25
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
26
|
+
pkg.gem_spec = spec
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::TestTask.new do |t|
|
30
|
+
t.libs << 'test'
|
31
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
32
|
+
t.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Generate the gemspec to serve this Gem from Github'
|
36
|
+
task :github do
|
37
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
38
|
+
File.open(file, 'w') {|f| f << spec.to_ruby }
|
39
|
+
puts "Created gemspec: #{file}"
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sprockets'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
|
7
|
+
module SprocketsSinatra
|
8
|
+
CONFIG = YAML.load_file(File.join(Sinatra::Application.root,'config',"sprockets.yml"))
|
9
|
+
CONFIG[:file_name] ||= 'sprockets'
|
10
|
+
CONFIG[:asset_root] ||= 'public'
|
11
|
+
CONFIG[:load_path] ||= ['javascripts', 'vendor/sprockets/*/src', 'vendor/plugins/*/javascripts']
|
12
|
+
CONFIG[:source_files] ||= ['javascripts/application.js']
|
13
|
+
CONFIG[:cache_control] ||= 'public, max-age=86400' # cache for 24 hours
|
14
|
+
|
15
|
+
|
16
|
+
module Helpers
|
17
|
+
def sprockets_include_tag(asset_host = '')
|
18
|
+
"<script src='#{asset_host}/#{CONFIG[:file_name]}.js#{"?#{Time.now.to_i}" if Sinatra::Application.environment.to_s == 'development'}' type='text/javascript'></script>"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def self.registered(app)
|
24
|
+
app.helpers SprocketsSinatra::Helpers
|
25
|
+
app.get "/sprockets-sinatra-test" do
|
26
|
+
SprocketsSinatra::CONFIG ? "sprockets-sinatra is ready :)" : "sprockets-sinatra is not ready :("
|
27
|
+
end
|
28
|
+
app.get "/#{SprocketsSinatra::CONFIG[:file_name]}.js" do
|
29
|
+
secretary = Sprockets::Secretary.new(SprocketsSinatra::CONFIG.merge(:root => Sinatra::Application.root))
|
30
|
+
content_type "text/javascript; charset=utf-8"
|
31
|
+
headers['Cache-Control'] = SprocketsSinatra::CONFIG[:cache_control]
|
32
|
+
secretary.concatenation.to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
register SprocketsSinatra
|
38
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kelredd-sprockets-sinatra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kelredd
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-21 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: kelredd@example.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- Rakefile
|
27
|
+
- lib/sprockets_sinatra
|
28
|
+
- lib/sprockets_sinatra/base.rb
|
29
|
+
- lib/sprockets_sinatra/version.rb
|
30
|
+
- lib/sprockets_sinatra.rb
|
31
|
+
- test/test_helper.rb
|
32
|
+
- test/unit
|
33
|
+
- test/unit/sprockets_sinatra_test.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://kelredd.com
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --main
|
39
|
+
- README.rdoc
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.2.0
|
58
|
+
signing_key:
|
59
|
+
specification_version: 2
|
60
|
+
summary: This gem extends a sinatra app with helpers for using sprockets.
|
61
|
+
test_files: []
|
62
|
+
|