asset_finder 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16b0b842afe8faed13754e7b9fcc9b4d686f877e
4
- data.tar.gz: da93b866f172d008b1975dfe58494d9b2f412392
3
+ metadata.gz: 9b7c4625c410c3e792d6f01895b84a359fcbc0a9
4
+ data.tar.gz: f2d8f9e42fddd988a9517ec53b7c2f75692aa185
5
5
  SHA512:
6
- metadata.gz: 345214ad7fffa936fb69b3fa00bd462441f9ae13e5c135e72aa00e5a596d1a72a1c462bdb63824a1cdb8f12b10f129471993b9ea6c09b307a22f29ef3d095147
7
- data.tar.gz: 5af4489fe4b2b595842dfec76db716e45c7e6e91380690772ce1eae3fc7fb97d291cb3f38d7567fd60ef574f793e1f44e87397dd924cd3d07651c9c3b73c6ba1
6
+ metadata.gz: 3a67724343d7edf47c507eaad21e8fd9876203315ea5d27164f93c33eb93584c48f9367247dcde541225c56bc92e04ce2d0655a16ce4eed0370705d16a795d1d
7
+ data.tar.gz: e4c3471fa9e63c8acf5ffe43ce1a96eb8ea28d704fe796d87fd3cfe44bc7855972bff5537ea492c604bb26f95f6641d07820f845d5a8a32e8430d40df1412826
@@ -1,4 +1,5 @@
1
1
  require "asset_finder/version"
2
+ require "asset_finder/configuration"
2
3
  require "asset_finder/finder"
3
4
  require "asset_finder/javascript/normalizer"
4
5
  require "asset_finder/javascript/finder"
@@ -7,5 +8,12 @@ require "asset_finder/stylesheet/finder"
7
8
  require "asset_finder/railtie" if defined?(::Rails::Railtie)
8
9
 
9
10
  module AssetFinder
10
- # Your code goes here...
11
+ class << self
12
+ attr_accessor :configuration
13
+ end
14
+
15
+ def self.configure
16
+ self.configuration ||= Configuration.new
17
+ yield(self.configuration)
18
+ end
11
19
  end
@@ -0,0 +1,16 @@
1
+ module AssetFinder
2
+ class Configuration
3
+ attr_accessor :javascript_patterns, :stylesheet_patterns
4
+
5
+ DEFAULT = {
6
+ javascript_patterns: [],
7
+ stylesheet_patterns: []
8
+ }.freeze
9
+
10
+ def initialize(options = {})
11
+ %i(javascript_patterns stylesheet_patterns).each do |k|
12
+ send(:"#{k}=", options[k] || DEFAULT[k])
13
+ end
14
+ end
15
+ end
16
+ end
@@ -6,12 +6,12 @@ module AssetFinder
6
6
  def self.execute
7
7
  [].tap do |paths|
8
8
  root_dir = File.join(Rails.root, 'app/assets/javascripts/')
9
- norimalizer = Normalizer.new(root_dir)
9
+ normalizer = Normalizer.new(root_dir, AssetFinder.configuration.javascript_patterns)
10
10
 
11
11
  Find.find(root_dir).each do |path|
12
- norimalized_path = norimalizer.norimalize(path)
13
- next if norimalized_path.nil?
14
- paths << norimalized_path
12
+ normalized_path = normalizer.normalize(path)
13
+ next if normalized_path.nil?
14
+ paths << normalized_path
15
15
  end
16
16
  end
17
17
  end
@@ -1,22 +1,24 @@
1
1
  module AssetFinder
2
2
  module Javascript
3
3
  class Normalizer
4
- def initialize(root_dir)
4
+ DEFAULT_PATTERNS = [
5
+ /^(.*)\.js\.coffee$/,
6
+ /^(.*)\.coffee$/,
7
+ /^(.*)\.js$/
8
+ ].freeze
9
+
10
+ def initialize(root_dir, patterns = [])
5
11
  @root_dir = root_dir.to_s
12
+ @patterns = patterns + DEFAULT_PATTERNS
6
13
  end
7
14
 
8
- def norimalize(path)
9
- if path.match(/^(.*)\.js\.coffee$/)
10
- return $1.sub(@root_dir, '') + '.js'
11
- end
12
-
13
- if path.match(/^(.*)\.coffee$/)
14
- return $1.sub(@root_dir, '') + '.js'
15
- end
16
-
17
- if path.match(/^(.*)\.js$/)
18
- return $1.sub(@root_dir, '') + '.js'
15
+ def normalize(path)
16
+ @patterns.each do |pattern|
17
+ if path.match(pattern)
18
+ return $1.sub(@root_dir, '') + '.js'
19
+ end
19
20
  end
21
+ nil
20
22
  end
21
23
  end
22
24
  end
@@ -1,6 +1,15 @@
1
1
  module AssetFinder
2
2
  class Railtie < ::Rails::Railtie
3
- initializer 'Initialize asset_finder' do
3
+ config.asset_finder = ActiveSupport::OrderedOptions.new
4
+ config.asset_finder.javascript_patterns = []
5
+ config.asset_finder.stylesheet_patterns = []
6
+
7
+ config.to_prepare do
8
+ AssetFinder.configure do |config|
9
+ config.javascript_patterns = Rails.application.config.asset_finder.javascript_patterns
10
+ config.stylesheet_patterns = Rails.application.config.asset_finder.stylesheet_patterns
11
+ end
12
+
4
13
  Rails.application.config.assets.precompile += AssetFinder::Finder.execute
5
14
  end
6
15
  end
@@ -6,12 +6,12 @@ module AssetFinder
6
6
  def self.execute
7
7
  [].tap do |paths|
8
8
  root_dir = File.join(Rails.root, 'app/assets/stylesheets/')
9
- norimalizer = Normalizer.new(root_dir)
9
+ normalizer = Normalizer.new(root_dir, AssetFinder.configuration.stylesheet_patterns)
10
10
 
11
11
  Find.find(root_dir).each do |path|
12
- norimalized_path = norimalizer.norimalize(path)
13
- next if norimalized_path.nil?
14
- paths << norimalized_path
12
+ normalized_path = normalizer.normalize(path)
13
+ next if normalized_path.nil?
14
+ paths << normalized_path
15
15
  end
16
16
  end
17
17
  end
@@ -1,22 +1,24 @@
1
1
  module AssetFinder
2
2
  module Stylesheet
3
3
  class Normalizer
4
- def initialize(root_dir)
4
+ DEFAULT_PATTERNS = [
5
+ /^(.*)\.css\.scss$/,
6
+ /^(.*)\.css$/,
7
+ /^(.*)\.scss$/
8
+ ].freeze
9
+
10
+ def initialize(root_dir, patterns = [])
5
11
  @root_dir = root_dir.to_s
12
+ @patterns = patterns + DEFAULT_PATTERNS
6
13
  end
7
14
 
8
- def norimalize(path)
9
- if path.match(/^(.*)\.css\.scss$/)
10
- return $1.sub(@root_dir, '') + '.css'
11
- end
12
-
13
- if path.match(/^(.*)\.css$/)
14
- return $1.sub(@root_dir, '') + '.css'
15
- end
16
-
17
- if path.match(/^(.*)\.scss$/)
18
- return $1.sub(@root_dir, '') + '.css'
15
+ def normalize(path)
16
+ @patterns.each do |pattern|
17
+ if path.match(pattern)
18
+ return $1.sub(@root_dir, '') + '.css'
19
+ end
19
20
  end
21
+ nil
20
22
  end
21
23
  end
22
24
  end
@@ -1,3 +1,3 @@
1
1
  module AssetFinder
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Ooishi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -90,6 +90,7 @@ files:
90
90
  - bin/console
91
91
  - bin/setup
92
92
  - lib/asset_finder.rb
93
+ - lib/asset_finder/configuration.rb
93
94
  - lib/asset_finder/finder.rb
94
95
  - lib/asset_finder/javascript/finder.rb
95
96
  - lib/asset_finder/javascript/normalizer.rb