Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Add a :strip_comments option to Secretary that is passed through to i…
Browse files Browse the repository at this point in the history
…ts Preprocessor. [#12 state:resolved]
  • Loading branch information
sstephenson committed Mar 2, 2009
1 parent a09372e commit 8860b7f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
@@ -1,3 +1,8 @@
* Add a :strip_comments option to Secretary that is passed through to its Preprocessor. [#12 state:resolved]


*1.0.2* (February 24, 2009)

* Update the sprockets-rails installation instructions to use `script/plugin`. [#7 state:resolved]

* Fix Secretary#source_last_modified not to raise an exception when one of the preprocessor's source files has been moved or deleted. (Jonathan Goldman) [#10 state:resolved]
Expand Down
11 changes: 6 additions & 5 deletions lib/sprockets/secretary.rb
@@ -1,10 +1,11 @@
module Sprockets
class Secretary
DEFAULT_OPTIONS = {
:root => ".",
:load_path => [],
:source_files => [],
:expand_paths => true
:root => ".",
:load_path => [],
:source_files => [],
:expand_paths => true,
:strip_comments => true
}

attr_reader :environment, :preprocessor
Expand All @@ -16,7 +17,7 @@ def initialize(options = {})
def reset!(options = @options)
@options = DEFAULT_OPTIONS.merge(options)
@environment = Sprockets::Environment.new(@options[:root])
@preprocessor = Sprockets::Preprocessor.new(@environment)
@preprocessor = Sprockets::Preprocessor.new(@environment, :strip_comments => @options[:strip_comments])

add_load_locations(@options[:load_path])
add_source_files(@options[:source_files])
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/src/script_with_comments.js
@@ -0,0 +1,13 @@
/*
* Comment that should remain
*/

/**
* PDoc comment that should be stripped
**/

(function(){})();

// This should be stripped, too

with({}){}; // but not this
6 changes: 6 additions & 0 deletions test/test_secretary.rb
Expand Up @@ -76,6 +76,12 @@ def test_install_assets_into_subdirectories_that_already_exist
end
end

def test_secretary_passes_strip_comments_option_through_to_preprocessor
secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :strip_comments => false)
secretary.add_source_file("src/script_with_comments.js")
assert_equal content_of_fixture("src/script_with_comments.js"), secretary.concatenation.to_s
end

protected
def paths_relative_to(root, *paths)
paths.map { |path| File.join(root, path) }
Expand Down

0 comments on commit 8860b7f

Please sign in to comment.