hanami-assets 1.3.5 → 2.1.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +92 -314
- data/hanami-assets.gemspec +26 -33
- data/lib/hanami/assets/asset.rb +83 -0
- data/lib/hanami/assets/base_url.rb +64 -0
- data/lib/hanami/assets/config.rb +106 -0
- data/lib/hanami/assets/errors.rb +46 -0
- data/lib/hanami/assets/version.rb +2 -2
- data/lib/hanami/assets.rb +61 -143
- data/lib/hanami-assets.rb +3 -0
- metadata +33 -115
- data/lib/hanami/assets/bundler/asset.rb +0 -100
- data/lib/hanami/assets/bundler/compressor.rb +0 -63
- data/lib/hanami/assets/bundler/manifest_entry.rb +0 -64
- data/lib/hanami/assets/bundler.rb +0 -154
- data/lib/hanami/assets/cache.rb +0 -102
- data/lib/hanami/assets/compiler.rb +0 -287
- data/lib/hanami/assets/compilers/less.rb +0 -31
- data/lib/hanami/assets/compilers/sass.rb +0 -61
- data/lib/hanami/assets/compressors/abstract.rb +0 -119
- data/lib/hanami/assets/compressors/builtin_javascript.rb +0 -36
- data/lib/hanami/assets/compressors/builtin_stylesheet.rb +0 -57
- data/lib/hanami/assets/compressors/closure_javascript.rb +0 -25
- data/lib/hanami/assets/compressors/javascript.rb +0 -77
- data/lib/hanami/assets/compressors/jsmin.rb +0 -284
- data/lib/hanami/assets/compressors/null_compressor.rb +0 -19
- data/lib/hanami/assets/compressors/sass_stylesheet.rb +0 -36
- data/lib/hanami/assets/compressors/stylesheet.rb +0 -77
- data/lib/hanami/assets/compressors/uglifier_javascript.rb +0 -25
- data/lib/hanami/assets/compressors/yui_javascript.rb +0 -25
- data/lib/hanami/assets/compressors/yui_stylesheet.rb +0 -25
- data/lib/hanami/assets/config/global_sources.rb +0 -52
- data/lib/hanami/assets/config/manifest.rb +0 -142
- data/lib/hanami/assets/config/sources.rb +0 -80
- data/lib/hanami/assets/configuration.rb +0 -657
- data/lib/hanami/assets/helpers.rb +0 -945
- data/lib/hanami/assets/precompiler.rb +0 -97
@@ -1,142 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
module Assets
|
5
|
-
# This error is raised when the application starts but can't be load the
|
6
|
-
# manifest file.
|
7
|
-
#
|
8
|
-
# @since 0.1.0
|
9
|
-
# @api private
|
10
|
-
class MissingManifestFileError < Error
|
11
|
-
def initialize(path)
|
12
|
-
super("Can't read manifest: #{path}")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# This error is raised when an asset is referenced from the DOM, but it's
|
17
|
-
# not present in the manifest
|
18
|
-
#
|
19
|
-
# @since 0.1.0
|
20
|
-
# @api private
|
21
|
-
class MissingManifestAssetError < Error
|
22
|
-
def initialize(asset, manifest_path)
|
23
|
-
super("Can't find asset `#{asset}' in manifest (#{manifest_path})")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Configuration settings
|
28
|
-
#
|
29
|
-
# @since 0.1.0
|
30
|
-
# @api private
|
31
|
-
module Config
|
32
|
-
# Default value for configuration's manifest.
|
33
|
-
#
|
34
|
-
# It indicates that the manifest wasn't loaded yet.
|
35
|
-
#
|
36
|
-
# At the load time, this should be replaced by an instance of
|
37
|
-
# <tt>Hanami::Assets::Config::Manifest</tt>.
|
38
|
-
#
|
39
|
-
# If for some reason that won't happen, the instance of this class is
|
40
|
-
# still referenced by the configuration and all the method invocations
|
41
|
-
# will raise a <tt>Hanami::Assets::MissingManifestFileError</tt>.
|
42
|
-
#
|
43
|
-
# @since 0.1.0
|
44
|
-
# @api private
|
45
|
-
#
|
46
|
-
# @see Hanami::Assets::Configuration#manifest
|
47
|
-
# @see Hanami::Assets::Configuration#manifest_path
|
48
|
-
# @see Hanami::Assets::Configuration#fingerprint
|
49
|
-
class NullManifest < Utils::BasicObject
|
50
|
-
# Return a new instance
|
51
|
-
#
|
52
|
-
# @param configuration [Hanami::Assets::Configuration]
|
53
|
-
#
|
54
|
-
# @return [Hanami::Assets::Config::NullManifest] a new instance
|
55
|
-
#
|
56
|
-
# @since 0.1.0
|
57
|
-
# @api private
|
58
|
-
def initialize(configuration)
|
59
|
-
@configuration = configuration
|
60
|
-
end
|
61
|
-
|
62
|
-
# @raise [Hanami::Assets::MissingManifestFileError]
|
63
|
-
#
|
64
|
-
# @since 0.1.0
|
65
|
-
# @api private
|
66
|
-
def method_missing(*) # rubocop:disable Style/MethodMissingSuper
|
67
|
-
::Kernel.raise(
|
68
|
-
::Hanami::Assets::MissingManifestFileError.new(@configuration.manifest_path)
|
69
|
-
)
|
70
|
-
end
|
71
|
-
|
72
|
-
# @return [FalseClass] returns false
|
73
|
-
#
|
74
|
-
# @since 1.1.0
|
75
|
-
# @api private
|
76
|
-
def respond_to_missing?(*)
|
77
|
-
false
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# Manifest file
|
82
|
-
#
|
83
|
-
# @since 0.1.0
|
84
|
-
# @api private
|
85
|
-
class Manifest
|
86
|
-
# @since 0.4.0
|
87
|
-
# @api private
|
88
|
-
TARGET = "target"
|
89
|
-
|
90
|
-
# @since 0.3.0
|
91
|
-
# @api private
|
92
|
-
SUBRESOURCE_INTEGRITY = "sri"
|
93
|
-
|
94
|
-
# Return a new instance
|
95
|
-
#
|
96
|
-
# @param assets [Hash] the content of the manifest
|
97
|
-
# @param manifest_path [Pathname] the path to the manifest
|
98
|
-
#
|
99
|
-
# @return [Hanami::Assets::Config::Manifest] a new instance
|
100
|
-
#
|
101
|
-
# @since 0.1.0
|
102
|
-
# @api private
|
103
|
-
#
|
104
|
-
# @see Hanami::Assets::Configuration#manifest
|
105
|
-
# @see Hanami::Assets::Configuration#manifest_path
|
106
|
-
def initialize(assets, manifest_path)
|
107
|
-
@assets = assets
|
108
|
-
@manifest_path = manifest_path
|
109
|
-
end
|
110
|
-
|
111
|
-
# Resolve the given asset into a fingerprinted path
|
112
|
-
#
|
113
|
-
# For a given path <tt>/assets/application.js</tt> it will return
|
114
|
-
# <tt>/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js</tt>
|
115
|
-
#
|
116
|
-
# @param asset [#to_s] the relative asset path
|
117
|
-
#
|
118
|
-
# @return [String] the fingerprinted path
|
119
|
-
#
|
120
|
-
# @raise [Hanami::Assets::MissingManifestAssetError] when the asset can't be
|
121
|
-
# found in manifest
|
122
|
-
def resolve(asset)
|
123
|
-
@assets.fetch(asset.to_s) do
|
124
|
-
raise Hanami::Assets::MissingManifestAssetError.new(asset, @manifest_path)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
# @since 0.3.0
|
129
|
-
# @api private
|
130
|
-
def target(path)
|
131
|
-
resolve(path).fetch(TARGET)
|
132
|
-
end
|
133
|
-
|
134
|
-
# @since 0.3.0
|
135
|
-
# @api private
|
136
|
-
def subresource_integrity_values(path)
|
137
|
-
resolve(path).fetch(SUBRESOURCE_INTEGRITY)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami/utils/load_paths"
|
4
|
-
require "hanami/utils/file_list"
|
5
|
-
|
6
|
-
module Hanami
|
7
|
-
module Assets
|
8
|
-
# Configuration settings
|
9
|
-
#
|
10
|
-
# @since 0.1.0
|
11
|
-
# @api private
|
12
|
-
module Config
|
13
|
-
# Source directories for a specific application
|
14
|
-
#
|
15
|
-
# @since 0.1.0
|
16
|
-
# @api private
|
17
|
-
#
|
18
|
-
# @see Hanami::Assets.duplicate
|
19
|
-
# @see http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/LoadPaths
|
20
|
-
#
|
21
|
-
# TODO The perf of this class is poor, consider to improve it.
|
22
|
-
class Sources < Utils::LoadPaths
|
23
|
-
# @since 0.3.0
|
24
|
-
# @api private
|
25
|
-
SKIPPED_FILE_PREFIX = "_"
|
26
|
-
|
27
|
-
# @since 0.1.0
|
28
|
-
# @api private
|
29
|
-
attr_writer :root
|
30
|
-
|
31
|
-
# @since 0.1.0
|
32
|
-
# @api private
|
33
|
-
def initialize(root)
|
34
|
-
super()
|
35
|
-
@root = root
|
36
|
-
end
|
37
|
-
|
38
|
-
# @since 0.1.0
|
39
|
-
# @api private
|
40
|
-
def map
|
41
|
-
[].tap do |result|
|
42
|
-
each do |source|
|
43
|
-
result << yield(source)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# @since 0.1.0
|
49
|
-
# @api private
|
50
|
-
def find(filename)
|
51
|
-
result = files(filename).first
|
52
|
-
result = Pathname.new(result) unless result.nil?
|
53
|
-
result
|
54
|
-
end
|
55
|
-
|
56
|
-
# @since 0.1.0
|
57
|
-
# @api private
|
58
|
-
def files(name = nil)
|
59
|
-
result = []
|
60
|
-
|
61
|
-
Utils::FileList[map { |source| "#{source}#{::File::SEPARATOR}**#{::File::SEPARATOR}#{name}*" }].each do |file|
|
62
|
-
next if ::File.directory?(file) || ::File.basename(file).start_with?(SKIPPED_FILE_PREFIX)
|
63
|
-
|
64
|
-
result << file
|
65
|
-
end
|
66
|
-
|
67
|
-
result
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
# @since 0.1.0
|
73
|
-
# @api private
|
74
|
-
def realpath(path)
|
75
|
-
@root.join(path).realpath
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|