tension 0.9.15 → 0.9.16.pre

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: 4eaa058ee2622eb39b664cc7ba46ec0764421d94
4
- data.tar.gz: 552a3bff4bbae5383b983151b881729bab24acaf
3
+ metadata.gz: 24de161fcb938eff0187dbd00f57303069e91f30
4
+ data.tar.gz: 3c80a48d9e2a993b674a8a013a683844c5c8d8e3
5
5
  SHA512:
6
- metadata.gz: a711ab02daf23f6f578a2a006864ebf422668317e5f09d11b63104403bdf587041ec4779985efcd4fe6714b0f4e1e0ab1a363dcf8e05b010a3822106a11c270d
7
- data.tar.gz: 03efbcd1cdd7f00fc53c8da818c2ff9a0942a348463414b361a5d56d61d23836eb0ca0d5f902131e84e3fae589b58e44bbaef4cb3da8bf16a5073bd863638c0d
6
+ metadata.gz: c7ca25fdaec1bfb1662ae15cf76695db9941ab8a3ff34dced421abfd1d4f8b67bc7179385cc121030ad6f113bacbab274575a5b236c02ffe98e311a220267488
7
+ data.tar.gz: 7987f999f4ca991e21692d3c27a06578a24b16fd6e8a6ecc7d32bdcf3ec841458859dee13a72243f9c9c464e5346cdf531e4dd9da9415497d99abc8beecf7b79
@@ -1,9 +1,13 @@
1
1
  module Tension
2
2
  class Context
3
- attr_reader :controller, :action
3
+ attr_reader :controller_name, :action
4
4
 
5
5
  def initialize(controller_path)
6
- @controller = "#{ controller_path }_controller".classify.constantize
6
+ @controller_name = "#{ controller_path }_controller".classify
7
+ end
8
+
9
+ def controller
10
+ controller_name.constantize
7
11
  end
8
12
 
9
13
  # Locates the best stylesheet for the given action name. Aliased as,
@@ -43,13 +47,17 @@ module Tension
43
47
  controller.action_methods.include?(action_name)
44
48
  end
45
49
 
50
+ def shared_assets
51
+ controller._tension_assets
52
+ end
53
+
46
54
 
47
55
  private
48
56
 
49
57
  # Locates the best asset for the given action name and type.
50
58
  #
51
59
  def best_asset(action, type)
52
- action_asset(action, type) || controller_asset(type) || global_asset(type)
60
+ action_asset(action, type) || controller_asset(type)
53
61
  end
54
62
 
55
63
  def method_missing(method_sym, *args)
@@ -7,14 +7,20 @@ module Tension
7
7
  included do
8
8
  # Make these methods available in helpers too.
9
9
  helper_method :asset_context, :action_javascript, :action_stylesheet
10
+
11
+ class_attribute :_tension_assets, instance_accessor: false
12
+ self._tension_assets = {}
10
13
  end
11
14
 
12
- # Returns the Context for the current controller.
13
- #
14
- def asset_context
15
- find_asset_context( request.symbolized_path_parameters[:controller] )
15
+
16
+ module ClassMethods
17
+ def include_assets(options)
18
+ self._tension_assets[ Tension::CSS ] = options[:css]
19
+ self._tension_assets[ Tension::JS ] = options[:js]
20
+ end
16
21
  end
17
22
 
23
+
18
24
  # Returns the Sprockets Asset for the current action's JavaScript
19
25
  # to be written into the template.
20
26
  #
@@ -29,6 +35,13 @@ module Tension
29
35
  asset_context.css( request.symbolized_path_parameters[:action] )
30
36
  end
31
37
 
38
+
39
+ # Returns the Context for the current controller.
40
+ #
41
+ def asset_context
42
+ find_asset_context( request.symbolized_path_parameters[:controller] )
43
+ end
44
+
32
45
  # Proxy to Tension::Environment.find.
33
46
  #
34
47
  def find_asset_context(*args)
@@ -7,30 +7,52 @@ module Tension
7
7
  module Helper
8
8
  extend ActiveSupport::Concern
9
9
 
10
- # Determines the best stylesheet to be included in a template based
10
+ # Determines the best stylesheets to be included in a template based
11
11
  # on the current controller and action.
12
12
  #
13
- def best_stylesheet(*args)
14
- asset_for( Tension::CSS, *args )
13
+ def best_stylesheets(*args)
14
+ build_tags( Tension::CSS, *args )
15
15
  end
16
16
 
17
- # Determines the best JavaScript to be included in a template based
17
+ # Determines the best JavaScripts to be included in a template based
18
18
  # on the current controller and action.
19
19
  #
20
- def best_javascript(*args)
21
- asset_for( Tension::JS, *args )
20
+ def best_javascripts(*args)
21
+ build_tags( Tension::JS, *args )
22
22
  end
23
23
 
24
24
  private
25
25
 
26
- def asset_for(type, *args)
26
+ def build_tags(type, *args)
27
+ options = args.extract_options!
28
+ shared_path = options.delete(:shared) || asset_context.shared_assets[type].presence
29
+
30
+ html = asset_for( type, "application", *args, options )
31
+
32
+ if shared_path
33
+ html << asset_for( type, shared_path, *args )
34
+ end
35
+
36
+ # action_asset = case type
37
+ # when Tension::CSS
38
+ # action_stylesheet
39
+ # when Tension::JS
40
+ # action_javascript
41
+ # end
42
+
43
+ # html << asset_for( type, action_asset.logical_path, *args, options )
44
+
45
+ html.html_safe
46
+ end
47
+
48
+ def asset_for(type, path, *args)
27
49
  return nil if asset_context.nil?
28
50
 
29
- case type.to_sym
30
- when :js
31
- javascript_include_tag( action_javascript.logical_path, *args )
32
- when :css
33
- stylesheet_link_tag( action_stylesheet.logical_path, *args )
51
+ case type
52
+ when Tension::CSS
53
+ stylesheet_link_tag( path, *args )
54
+ when Tension::JS
55
+ javascript_include_tag( path, *args )
34
56
  end
35
57
  end
36
58
  end
@@ -1,3 +1,3 @@
1
1
  module Tension
2
- VERSION = "0.9.15".freeze
2
+ VERSION = "0.9.16.pre".freeze
3
3
  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.15
4
+ version: 0.9.16.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piers Mainwaring
@@ -57,9 +57,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
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
- version: '0'
62
+ version: 1.3.1
63
63
  requirements: []
64
64
  rubyforge_project:
65
65
  rubygems_version: 2.0.3