sprockets 1.0.0 → 1.0.1
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/ext/nph-sprockets.cgi +127 -0
- data/lib/sprockets/version.rb +1 -1
- metadata +3 -2
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# This is a simple CGI wrapper around Sprockets.
|
|
4
|
+
#
|
|
5
|
+
# Copy it into a directory on your site with CGI enabled. When invoked, the
|
|
6
|
+
# script will search its directory and parent directories for a YAML file named
|
|
7
|
+
# "config/sprockets.yml" in order to load configuration information.
|
|
8
|
+
#
|
|
9
|
+
# If you set the environment variable "sprockets_generate_output_file" to
|
|
10
|
+
# "true" the concatenation will be cached to disk. Use it in conjunction with
|
|
11
|
+
# URL rewriting to cache your Sprockets output on the first request.
|
|
12
|
+
#
|
|
13
|
+
# Assuming a site layout like this:
|
|
14
|
+
#
|
|
15
|
+
# mysite/
|
|
16
|
+
# config/
|
|
17
|
+
# sprockets.yml
|
|
18
|
+
# javascripts/
|
|
19
|
+
# mysite.js
|
|
20
|
+
# ...
|
|
21
|
+
# public/
|
|
22
|
+
# index.html
|
|
23
|
+
# nph-sprockets.cgi (this file)
|
|
24
|
+
# vendor/
|
|
25
|
+
# sprockets/
|
|
26
|
+
# prototype/ -> ...
|
|
27
|
+
# scriptaculous/ -> ...
|
|
28
|
+
#
|
|
29
|
+
# mysite/config/sprockets.yml might look like this:
|
|
30
|
+
#
|
|
31
|
+
# :load_path:
|
|
32
|
+
# - javascripts
|
|
33
|
+
# - vendor/sprockets/*/src
|
|
34
|
+
# :source_files:
|
|
35
|
+
# - javascripts/mysite.js
|
|
36
|
+
# - javascripts/*.js
|
|
37
|
+
# :output_file: public/sprockets.js
|
|
38
|
+
#
|
|
39
|
+
# The <script> tag in mysite/public/index.html could look like this:
|
|
40
|
+
#
|
|
41
|
+
# <script type="text/javascript" src="/sprockets.js"></script>
|
|
42
|
+
#
|
|
43
|
+
# And you might have the following Apache configuration:
|
|
44
|
+
#
|
|
45
|
+
# <VirtualHost ...>
|
|
46
|
+
# ServerName mysite.example.org
|
|
47
|
+
# DocumentRoot "/path/to/mysite/public"
|
|
48
|
+
#
|
|
49
|
+
# <Directory "/path/to/mysite/public">
|
|
50
|
+
# Options +ExecCGI +FollowSymLinks
|
|
51
|
+
# AddHandler cgi-script .cgi
|
|
52
|
+
#
|
|
53
|
+
# RewriteEngine on
|
|
54
|
+
# RewriteCond /sprockets.js !-f
|
|
55
|
+
# RewriteRule ^sprockets\.js /nph-sprockets.cgi [P,L]
|
|
56
|
+
# </Directory>
|
|
57
|
+
# </VirtualHost>
|
|
58
|
+
#
|
|
59
|
+
# All requests to /sprockets.js will transparently proxy /nph-sprockets.cgi if
|
|
60
|
+
# mysite/public/sprockets.js does not exist. In production, you can add
|
|
61
|
+
#
|
|
62
|
+
# SetEnv sprockets_generate_output_file true
|
|
63
|
+
#
|
|
64
|
+
# to your Apache configuration and mysites/public/sprockets.js will be cached
|
|
65
|
+
# on the first request to /sprockets.js.
|
|
66
|
+
|
|
67
|
+
require "yaml"
|
|
68
|
+
require "fileutils"
|
|
69
|
+
|
|
70
|
+
def respond_with(options = {})
|
|
71
|
+
options = { :code => 200, :content => "", :type => "text/plain" }.merge(options)
|
|
72
|
+
print "HTTP/1.0 #{options[:code]}\r\n"
|
|
73
|
+
print "Content-Type: #{options[:type]}\r\n"
|
|
74
|
+
print "Content-Length: #{options[:content].length}\r\n"
|
|
75
|
+
print "\r\n#{options[:content]}"
|
|
76
|
+
$stdout.flush
|
|
77
|
+
exit!
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def search_upwards_for(filename)
|
|
81
|
+
pwd = original_pwd = Dir.pwd
|
|
82
|
+
loop do
|
|
83
|
+
return File.expand_path(filename) if File.file?(filename)
|
|
84
|
+
Dir.chdir("..")
|
|
85
|
+
respond_with(:code => 500, :content => "couldn't find config/sprockets.yml") if Dir.pwd == pwd
|
|
86
|
+
pwd = Dir.pwd
|
|
87
|
+
end
|
|
88
|
+
ensure
|
|
89
|
+
Dir.chdir(original_pwd)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def generate_output_file?
|
|
93
|
+
(ENV["REDIRECT_sprockets_generate_output_file"] || ENV["sprockets_generate_output_file"]) =~ /true/i
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
configuration_file = search_upwards_for("config/sprockets.yml")
|
|
97
|
+
sprockets_root = File.dirname(File.dirname(configuration_file))
|
|
98
|
+
configuration = YAML.load(IO.read(configuration_file))
|
|
99
|
+
|
|
100
|
+
begin
|
|
101
|
+
if File.directory?(sprockets_dir = File.join(sprockets_root, "vendor/gems/sprockets/lib"))
|
|
102
|
+
$:.unshift sprockets_dir
|
|
103
|
+
elsif File.directory?(sprockets_dir = File.join(sprockets_root, "vendor/sprockets/lib"))
|
|
104
|
+
$:.unshift sprockets_dir
|
|
105
|
+
else
|
|
106
|
+
require "rubygems"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
require "sprockets"
|
|
110
|
+
|
|
111
|
+
rescue Exception => e
|
|
112
|
+
respond_with(:code => 500, :content => "couldn't find sprockets: #{e}")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
begin
|
|
116
|
+
secretary = Sprockets::Secretary.new(
|
|
117
|
+
:root => sprockets_root,
|
|
118
|
+
:load_path => configuration[:load_path],
|
|
119
|
+
:source_files => configuration[:source_files]
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
secretary.concatenation.save_to(File.join(sprockets_root, configuration[:output_file])) if generate_output_file?
|
|
123
|
+
respond_with(:content => secretary.concatenation.to_s, :type => "text/javascript")
|
|
124
|
+
|
|
125
|
+
rescue Exception => e
|
|
126
|
+
respond_with(:code => 500, :content => "couldn't generate concatenated javascript: #{e}")
|
|
127
|
+
end
|
data/lib/sprockets/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sprockets
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sam Stephenson
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-02-
|
|
12
|
+
date: 2009-02-19 00:00:00 -06:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -66,6 +66,7 @@ files:
|
|
|
66
66
|
- test/test_secretary.rb
|
|
67
67
|
- test/test_source_file.rb
|
|
68
68
|
- test/test_source_line.rb
|
|
69
|
+
- ext/nph-sprockets.cgi
|
|
69
70
|
has_rdoc: false
|
|
70
71
|
homepage: http://getsprockets.org/
|
|
71
72
|
post_install_message:
|