Skip to content

Commit 0a67473

Browse files
committed
first draft of jammit_debug
1 parent bcbe8fe commit 0a67473

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ <h2 id="configuration">Configuration</h2>
251251
to compress your JavaScript.
252252
</td>
253253
</tr>
254+
<tr>
255+
<td><b>allow_debugging</b></td>
256+
<td><tt>on&nbsp;|&nbsp;off</tt></td>
257+
<td class="definition">
258+
Defaults to <b>on</b>. Leaving it on allows you to pass
259+
<tt>jammit_debug=true</tt> as a query parameter, in order to load the
260+
page with uncompressed, unpackaged assets in production.
261+
</td>
262+
</tr>
254263
<tr>
255264
<td><b>template_function</b></td>
256265
<td><tt>on&nbsp;|&nbsp;off&nbsp;|&nbsp;...</tt></td>
@@ -349,6 +358,12 @@ <h2 id="usage">Usage</h2>
349358
In all other environments, or if <b>package_assets</b> is set to "<b>always</b>",
350359
you'll get tags for the merged packages.
351360
</p>
361+
362+
<p>
363+
If <b>allow_debugging</b> is left on, you'll be able to request the development
364+
version of the assets for any given page, by passing <tt>jammit_debug=true</tt>
365+
as a query parameter.
366+
</p>
352367

353368
<p>
354369
You can easily use Jammit within your Rakefile, and other scripts:

lib/jammit.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class << self
5050
:embed_assets, :package_assets, :compress_assets, :gzip_assets,
5151
:package_path, :mhtml_enabled, :include_jst_script, :config_path,
5252
:javascript_compressor, :compressor_options, :css_compressor_options,
53-
:template_extension, :template_extension_matcher
53+
:template_extension, :template_extension_matcher, :allow_debugging
5454
end
5555

5656
# The minimal required configuration.
@@ -70,6 +70,7 @@ def self.load_configuration(config_path, soft=false)
7070
@embed_assets = conf[:embed_assets] || conf[:embed_images]
7171
@compress_assets = !(conf[:compress_assets] == false)
7272
@gzip_assets = !(conf[:gzip_assets] == false)
73+
@allow_debugging = !(conf[:allow_debugging] == false)
7374
@mhtml_enabled = @embed_assets && @embed_assets != "datauri"
7475
@compressor_options = symbolize_keys(conf[:compressor_options] || {})
7576
@css_compressor_options = symbolize_keys(conf[:css_compressor_options] || {})

lib/jammit/helper.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module Helper
1616
# compressed CSS, and in development the stylesheet URLs are passed verbatim.
1717
def include_stylesheets(*packages)
1818
options = packages.extract_options!
19-
return individual_stylesheets(packages, options) unless Jammit.package_assets
19+
return individual_stylesheets(packages, options) unless should_package?
2020
disabled = (options.delete(:embed_assets) == false) || (options.delete(:embed_images) == false)
2121
return html_safe(packaged_stylesheets(packages, options)) if disabled || !Jammit.embed_assets
2222
return html_safe(embedded_image_stylesheets(packages, options))
@@ -26,7 +26,7 @@ def include_stylesheets(*packages)
2626
# except in development, where it references the individual scripts.
2727
def include_javascripts(*packages)
2828
tags = packages.map do |pack|
29-
Jammit.package_assets ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js)
29+
should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js)
3030
end
3131
html_safe(javascript_include_tag(tags.flatten))
3232
end
@@ -40,6 +40,10 @@ def include_templates(*packages)
4040

4141
private
4242

43+
def should_package?
44+
Jammit.package_assets && !(Jammit.allow_debugging && params[:jammit_debug])
45+
end
46+
4347
def html_safe(string)
4448
string.respond_to?(:html_safe) ? string.html_safe : string
4549
end

test/unit/test_jammit_helpers.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def initialize(*args)
2727
end
2828
end
2929

30+
def params
31+
@debug ? {:jammit_debug => true} : {}
32+
end
33+
3034
def test_include_stylesheets
3135
assert include_stylesheets(:css_test) == File.read('test/fixtures/tags/css_includes.html')
3236
end
@@ -51,7 +55,7 @@ def test_include_templates_with_diff_ext
5155
assert include_javascripts(:jst_test_diff_ext) == '<script src="/assets/jst_test_diff_ext.js?101" type="text/javascript"></script>'
5256
end
5357

54-
def test_individual_assets_in_development_do
58+
def test_individual_assets_in_development
5559
Jammit.instance_variable_set(:@package_assets, false)
5660
assert include_stylesheets(:css_test) == File.read('test/fixtures/tags/css_individual_includes.html')
5761
assert include_javascripts(:js_test_with_templates) == File.read('test/fixtures/tags/js_individual_includes.html')
@@ -64,4 +68,11 @@ def test_individual_assets_in_development_do
6468
Jammit.reload!
6569
end
6670

71+
def test_individual_assets_while_debugging
72+
@debug = true
73+
assert include_stylesheets(:css_test) == File.read('test/fixtures/tags/css_individual_includes.html')
74+
assert include_javascripts(:js_test_with_templates) == File.read('test/fixtures/tags/js_individual_includes.html')
75+
@debug = false
76+
end
77+
6778
end

0 commit comments

Comments
 (0)