catalyst-rails 0.0.4 → 0.0.5

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
  SHA256:
3
- metadata.gz: 9d92e6653287b8f5235dd06658dee2dd571743bc6e08f903747a2a86ba1b64b8
4
- data.tar.gz: 12854757d0594c4a409d95b1e920516d5a4d25a06970de08c98907889a2c5d9b
3
+ metadata.gz: 45f276a4db53b08c80aca358632f1fd2bf9d1fee132fcb9ed2db9a96f8454c7b
4
+ data.tar.gz: fae2b667b0302d140811d869bef7be5c8f6f9d849ab1b8e7805ebd3003a620dd
5
5
  SHA512:
6
- metadata.gz: 27c5ce372e4ee0254ea57a15fc25401499d12fbde0001722c413d74986663e0d0271b5e08b6c79aa1cef2ea9e5c9bbc78a83e3fea79ec75f0dce9a65146db8bd
7
- data.tar.gz: a3b4801399815e6d3c174ff04dcf96d1a364c73c343a0b5c4d9c2ca682d24f7b0970fecc65433987d4eeb06117681b0498633f134486233346e882f8a5d91cf1
6
+ metadata.gz: 05ca2857dea876499f66d32f119f28d5f666e4deebd79f58082b57ad8e3926f28fab0a70111992209e0254e7d1df5f8e1dde1573be5b373c049e2685ce58417c
7
+ data.tar.gz: f74c8becccb4d5788be14ba88334087b341ed3954687e182987891c4790fc55a343f6c7651894a81297b300aad2f558a4d1e6fd796ac86d4deee4118165461d5
@@ -6,36 +6,81 @@ require_relative './manifest'
6
6
  module Catalyst
7
7
  module Helpers
8
8
  include ActionView::Helpers::TagHelper
9
+ include ActionView::Helpers::OutputSafetyHelper
9
10
 
10
- def catalyst_javascript_vendor_include_tag
11
- if Catalyst.development?
12
- catalyst_javascript_include_tag('vendor-dll')
11
+ def catalyst_javascript_include_tag(path)
12
+ path = path.to_s.sub(/\.js\z/, '') + '.js'
13
+
14
+ if catalyst_referenced_files.include?(path)
15
+ raise ::Catalyst::Manifest::DuplicateAssetReference,
16
+ "The asset \"#{path}\" has already been referenced."
13
17
  end
18
+
19
+ catalyst_referenced_files << path
20
+
21
+ safe_join([
22
+ catalyst_javascript_vendor_include_tag,
23
+ catalyst_javascript_common_include_tag,
24
+ content_tag(
25
+ :script,
26
+ nil,
27
+ type: 'text/javascript',
28
+ crossorigin: 'anonymous',
29
+ src: ::Catalyst::Manifest[path]
30
+ )
31
+ ])
14
32
  end
15
33
 
16
- def catalyst_javascript_include_tag(path)
17
- path = path.to_s.gsub(/\.js\z/, '')
34
+ def catalyst_javascript_vendor_include_tag
35
+ path = 'vendor-dll.js'
36
+
37
+ return nil unless ::Catalyst.development?
38
+ return nil if catalyst_referenced_files.include?(path)
39
+
40
+ catalyst_javascript_include_tag(path)
41
+ end
18
42
 
19
- content_tag(
20
- :script,
21
- nil,
22
- type: 'text/javascript',
23
- crossorigin: 'anonymous',
24
- src: ::Catalyst::Manifest["#{path}.js"]
25
- )
43
+ def catalyst_javascript_common_include_tag
44
+ path = 'common.js'
45
+
46
+ return nil if catalyst_referenced_files.include?(path)
47
+
48
+ if ::Catalyst.development? || ::Catalyst::Manifest.has?(path)
49
+ catalyst_javascript_include_tag(path)
50
+ end
26
51
  end
27
52
 
28
53
  def catalyst_stylesheet_link_tag(path)
29
- path = path.to_s.gsub(/\.css\z/, '')
54
+ return nil if ::Catalyst.development?
55
+
56
+ path = path.to_s.sub(/\.css\z/, '') + '.css'
57
+
58
+ if catalyst_referenced_files.include?(path)
59
+ raise ::Catalyst::Manifest::DuplicateAssetReference,
60
+ "The asset \"#{path}\" has already been referenced."
61
+ end
62
+
63
+ catalyst_referenced_files << path
30
64
 
31
- unless Catalyst.development?
65
+ safe_join([
66
+ catalyst_common_stylesheet_link_tag,
32
67
  content_tag(
33
68
  :link,
34
69
  nil,
35
- href: ::Catalyst::Manifest["#{path}.css"],
70
+ href: ::Catalyst::Manifest[path],
36
71
  media: 'screen',
37
72
  rel: 'stylesheet'
38
73
  )
74
+ ])
75
+ end
76
+
77
+ def catalyst_common_stylesheet_link_tag
78
+ path = 'common.css'
79
+
80
+ return nil if catalyst_referenced_files.include?(path)
81
+
82
+ if ::Catalyst::Manifest.has?(path)
83
+ catalyst_stylesheet_link_tag(path)
39
84
  end
40
85
  end
41
86
 
@@ -44,11 +89,15 @@ module Catalyst
44
89
  end
45
90
 
46
91
  def catalyst_asset_url(path)
47
- if Catalyst.development? || Catalyst.config.assets_host.nil?
92
+ if ::Catalyst.development? || ::Catalyst.config.assets_host.nil?
48
93
  catalyst_asset_path(path)
49
94
  else
50
95
  "#{Catalyst.config.assets_host_protocol}://#{Catalyst.config.assets_host}#{catalyst_asset_path(path)}"
51
96
  end
52
97
  end
98
+
99
+ def catalyst_referenced_files
100
+ @catalyst_referenced_files ||= Set.new
101
+ end
53
102
  end
54
103
  end
@@ -3,15 +3,18 @@
3
3
  require 'singleton'
4
4
  require 'forwardable'
5
5
 
6
+ require_relative './errors'
7
+
6
8
  module Catalyst
7
9
  class Manifest
8
- AssetMissing = Class.new(StandardError)
10
+ AssetMissing = Class.new(::Catalyst::CatalystError)
11
+ DuplicateAssetReference = Class.new(::Catalyst::CatalystError)
9
12
 
10
13
  include Singleton
11
14
 
12
15
  class << self
13
16
  extend Forwardable
14
- def_delegator :instance, :[]
17
+ def_delegators :instance, :[], :has?
15
18
  end
16
19
 
17
20
  def initialize
@@ -26,6 +29,16 @@ module Catalyst
26
29
  end
27
30
  end
28
31
 
32
+ def has?(path)
33
+ path = path.to_s.gsub(/\A\/+/, '')
34
+
35
+ if Catalyst.development?
36
+ false
37
+ else
38
+ @manifest.key?(path)
39
+ end
40
+ end
41
+
29
42
  def [](path)
30
43
  path = path.to_s.gsub(/\A\/+/, '')
31
44
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Catalyst
4
4
  def self.version
5
- Gem::Version.new('0.0.4')
5
+ Gem::Version.new('0.0.5')
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catalyst-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Martens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-29 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable