tension 0.9.13 → 0.9.14

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64b25b44ab03279d7f615039ff68af05f90938db
4
- data.tar.gz: 1cc11db047e788ec6e2588bfded8038e8845eb63
3
+ metadata.gz: a75cab3b3ef65c9590305e2ae0743398a5326968
4
+ data.tar.gz: 9ff656abe44e288d6ee0e8ea2a8c3bfbcf0725f6
5
5
  SHA512:
6
- metadata.gz: b1222f9a47a84c9ec680514d44bf980247b47893af75ff1a79a326c0da18512b7c3f0eea2e0f80c3839ee716503630d59d2bd25771f75fd2fd24f85afc0df277
7
- data.tar.gz: 53cc3417937484fc3c18d71af10226e9f1b6e831544ab8911bd21a6e4f038f39c5517607333ce0d732a7046bfbc5d98e6a8b4b7e1209f046db2b40c5ddfa0971
6
+ metadata.gz: 94bfedf19b85e67862a66b352e9cc2b439a357d3389a031993ba6236b0e213f7f7d97d3089f441c6a826d31a2f849a78ca88b418942cee37115b2afaeddad31a
7
+ data.tar.gz: fc08ff6e486a0c43564c7ee934617bde46a33cc58d99926dfcbd77622052737e799cc9838cab327d39391a1eff0d38a6d49f8f1e9834041ce0c68087959cce81
@@ -32,7 +32,7 @@ module Tension
32
32
  # Proxy to Tension::Environment.find.
33
33
  #
34
34
  def find_asset_context(*args)
35
- Tension::Environment.find(*args)
35
+ Tension.environment.find_context(*args)
36
36
  end
37
37
  end
38
38
  end
@@ -4,67 +4,81 @@ module Tension
4
4
  # the assets to be included in templates.
5
5
  #
6
6
  class Environment
7
- class << self
8
7
 
9
- # Loads a Context for the specified controller path.
10
- #
11
- def find(key)
12
- fetch( Tension::Utils.controller_path(key) )
13
- end
14
- alias_method :[], :find
8
+ attr_reader :assets
15
9
 
16
- # A Hash mapping controller paths to Contexts.
17
- #
18
- def contexts
19
- @contexts ||= Hash.new
20
- end
10
+ def initialize(assets_path)
11
+ @manifest = Sprockets::Manifest.new(assets_path)
12
+ process_assets!
13
+ end
21
14
 
22
- # Preloads all Contexts. Useful in environments where assets and controller
23
- # actions don't change without an app reboot (production, staging).
24
- #
25
- def eager_load!
26
- configured_get_defaults.each do |default|
27
- find(default[:controller])
28
- end
15
+ # Loads a Context for the specified controller path.
16
+ #
17
+ def find_context(key)
18
+ fetch( Tension::Utils.controller_path(key) )
19
+ end
20
+ alias_method :[], :find_context
29
21
 
30
- true
31
- end
22
+ # A Hash mapping controller paths to Contexts.
23
+ #
24
+ def contexts
25
+ @contexts ||= Hash.new
26
+ end
32
27
 
33
- # Determines whether or not a given path refers to an asset that requires
34
- # precompilation.
35
- #
36
- def precompilation_needed?(path)
37
- if cxt = find(path)
38
- Tension::Utils.shared_asset?(path) || cxt.has_action?( Tension::Utils.action_name(path) )
39
- end
28
+ # Determines whether or not a given path refers to an asset that requires
29
+ # precompilation.
30
+ #
31
+ def precompilation_needed?(path)
32
+ if cxt = find_context(path)
33
+ Tension::Utils.shared_asset?(path) || cxt.has_action?( Tension::Utils.action_name(path) )
40
34
  end
35
+ end
41
36
 
42
37
 
43
- private
38
+ private
44
39
 
45
- def fetch(path)
46
- contexts[path] || store(path) unless path.nil?
47
- end
40
+ def fetch(path)
41
+ contexts[path] || store(path) unless path.nil?
42
+ end
48
43
 
49
- def store(path)
50
- contexts[path] ||= Context.new(path) if valid_route?(path)
51
- end
44
+ def store(path)
45
+ contexts[path] ||= Context.new(path) if valid_route?(path)
46
+ end
52
47
 
53
- def valid_route?(controller)
54
- configured_get_defaults.find do |default|
55
- default[:controller] == controller
56
- end
48
+ def valid_route?(controller)
49
+ configured_get_defaults.find do |default|
50
+ default[:controller] == controller
57
51
  end
52
+ end
53
+
54
+ def process_assets!
55
+ @assets = Hash.new
56
+ @manifest.files.each do |full_path, info|
57
+ next unless full_path.match(/\.css|\.js\z/)
58
58
 
59
- # Routing defaults (including controller path and action name) for all
60
- # configured GET routes.
61
- #
62
- def configured_get_defaults
63
- @configured_get_defaults ||= Rails.application.routes.routes.map do |route|
64
- route.defaults if route.verb.match("GET") && !route.defaults.empty?
65
- end.compact
59
+ info = info.merge(full_path: full_path).with_indifferent_access
60
+ @assets[ info[:logical_path] ] = Asset.new(info)
66
61
  end
62
+ end
63
+
64
+ # Routing defaults (including controller path and action name) for all
65
+ # configured GET routes.
66
+ #
67
+ def configured_get_defaults
68
+ @configured_get_defaults ||= Rails.application.routes.routes.map do |route|
69
+ route.defaults if route.verb.match("GET") && !route.defaults.empty?
70
+ end.compact
71
+ end
72
+
73
+ end
74
+
75
+ class Asset
76
+ def initialize(attributes)
77
+ @attributes = attributes
78
+ end
67
79
 
80
+ def logical_path
81
+ @attributes[:logical_path]
68
82
  end
69
83
  end
70
84
  end
@@ -9,10 +9,12 @@ module Tension
9
9
  ActionView::Base.send(:include, Tension::Helper)
10
10
  ActionController::Base.send(:include, Tension::Controller)
11
11
 
12
+ Tension.environment = Tension::Environment.new('public/assets')
13
+
12
14
  Rails.application.config.assets.precompile << lambda do |path, filename|
13
- Tension::Environment.precompilation_needed?(path)
15
+ Tension.environment.precompilation_needed?(path)
14
16
  end
15
17
  end
16
-
18
+
17
19
  end
18
20
  end
data/lib/tension/utils.rb CHANGED
@@ -18,9 +18,6 @@ module Tension
18
18
 
19
19
  elsif matches = path.split("#").first.match(CONTROLLER_REGEX)
20
20
  return matches[0]
21
-
22
- else
23
- return nil
24
21
  end
25
22
  end
26
23
 
@@ -45,14 +42,14 @@ module Tension
45
42
  # type: Tension::CSS
46
43
  #
47
44
  def find_asset(options)
48
- assets[ logical_asset_path(options) ]
45
+ Tension.environment.assets[ logical_asset_path(options) ]
49
46
  end
50
47
 
51
48
  # Returns the application-wide Sprockets Asset for the given type.
52
49
  # ARGS: type: Tension::JS or Tension::CSS
53
50
  #
54
51
  def global_asset(type)
55
- assets[ "application.#{type}" ]
52
+ Tension.environment.assets[ "application.#{type}" ]
56
53
  end
57
54
 
58
55
  private
@@ -71,12 +68,6 @@ module Tension
71
68
  end
72
69
  end
73
70
 
74
- # Alias for Sprockets' asset index.
75
- #
76
- def assets
77
- Rails.application.assets
78
- end
79
-
80
71
  # Takes an asset path like "comments/base/index.js" and determines
81
72
  # the controller ("comments/base") that should serve that asset.
82
73
  # ARGS: path: a String path like "admin/blog_common.css"
@@ -1,3 +1,3 @@
1
1
  module Tension
2
- VERSION = "0.9.13".freeze
2
+ VERSION = "0.9.14".freeze
3
3
  end
data/lib/tension.rb CHANGED
@@ -3,9 +3,18 @@ require 'tension/context'
3
3
  require 'tension/controller'
4
4
  require 'tension/helper'
5
5
  require 'tension/environment'
6
+ require 'tension/version'
6
7
  require 'tension/railtie' if defined?(Rails)
7
8
 
8
9
  module Tension
9
10
  CSS = "css".freeze
10
11
  JS = "js".freeze
12
+
13
+ def self.environment
14
+ @@environment
15
+ end
16
+
17
+ def self.environment=(env)
18
+ @@environment = env
19
+ end
11
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tension
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.13
4
+ version: 0.9.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piers Mainwaring
@@ -14,14 +14,14 @@ dependencies:
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  description: Tension brings some sanity to Rails's CSS & JS organization for modern
@@ -52,17 +52,17 @@ require_paths:
52
52
  - lib
53
53
  required_ruby_version: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - '>='
55
+ - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
64
  rubyforge_project:
65
- rubygems_version: 2.0.0
65
+ rubygems_version: 2.0.3
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: Tighten up Rails's asset pipeline for CSS & JS.