bunto-assets 1.0.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +19 -0
  3. data/LICENSE +21 -0
  4. data/README.md +275 -0
  5. data/Rakefile +3 -0
  6. data/lib/bunto/assets/addons/autoprefixer.rb +13 -0
  7. data/lib/bunto/assets/addons/bootstrap.rb +7 -0
  8. data/lib/bunto/assets/addons/font_awesome.rb +7 -0
  9. data/lib/bunto/assets/addons/javascript.rb +11 -0
  10. data/lib/bunto/assets/cached.rb +20 -0
  11. data/lib/bunto/assets/config.rb +76 -0
  12. data/lib/bunto/assets/env.rb +207 -0
  13. data/lib/bunto/assets/hook.rb +78 -0
  14. data/lib/bunto/assets/hooks/bunto/drops.rb +9 -0
  15. data/lib/bunto/assets/hooks/bunto/setup.rb +13 -0
  16. data/lib/bunto/assets/hooks/bunto/write.rb +9 -0
  17. data/lib/bunto/assets/hooks/cache.rb +15 -0
  18. data/lib/bunto/assets/hooks/compression.rb +17 -0
  19. data/lib/bunto/assets/hooks/configuration.rb +12 -0
  20. data/lib/bunto/assets/hooks/context.rb +11 -0
  21. data/lib/bunto/assets/hooks/erb.rb +15 -0
  22. data/lib/bunto/assets/hooks/helpers.rb +14 -0
  23. data/lib/bunto/assets/hooks/logger.rb +9 -0
  24. data/lib/bunto/assets/hooks/sources.rb +13 -0
  25. data/lib/bunto/assets/hooks/sprockets.rb +9 -0
  26. data/lib/bunto/assets/hooks/version.rb +11 -0
  27. data/lib/bunto/assets/hooks.rb +20 -0
  28. data/lib/bunto/assets/liquid/drop.rb +76 -0
  29. data/lib/bunto/assets/liquid/filters.rb +28 -0
  30. data/lib/bunto/assets/liquid/tag/defaults/image.rb +69 -0
  31. data/lib/bunto/assets/liquid/tag/defaults.rb +23 -0
  32. data/lib/bunto/assets/liquid/tag/parser.rb +200 -0
  33. data/lib/bunto/assets/liquid/tag/proxied_asset.rb +114 -0
  34. data/lib/bunto/assets/liquid/tag/proxies.rb +118 -0
  35. data/lib/bunto/assets/liquid/tag.rb +203 -0
  36. data/lib/bunto/assets/liquid.rb +15 -0
  37. data/lib/bunto/assets/logger.rb +59 -0
  38. data/lib/bunto/assets/patches/bunto/cleaner.rb +16 -0
  39. data/lib/bunto/assets/patches/bunto/site.rb +11 -0
  40. data/lib/bunto/assets/patches/kernel.rb +29 -0
  41. data/lib/bunto/assets/patches/sprockets/asset.rb +21 -0
  42. data/lib/bunto/assets/patches.rb +10 -0
  43. data/lib/bunto/assets/processors/liquid.rb +42 -0
  44. data/lib/bunto/assets/proxies/magick.rb +155 -0
  45. data/lib/bunto/assets/version.rb +11 -0
  46. data/lib/bunto/assets.rb +24 -0
  47. data/lib/bunto-assets.rb +7 -0
  48. metadata +197 -0
@@ -0,0 +1,155 @@
1
+ # ----------------------------------------------------------------------------
2
+ # Frozen-string-literal: true
3
+ # Copyright: 2016-present - MIT License
4
+ # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
6
+
7
+ try_require "mini_magick" do
8
+ args = %W(resize quality rotate crop flip gravity)
9
+ presets = %W(@2x @4x @1/2 @1/3 @2/3 @1/4 @2/4 @3/4
10
+ @double @quadruple @half @one-third @two-thirds @one-fourth
11
+ @two-fourths @three-fourths)
12
+
13
+ Bunto::Assets::Env.liquid_proxies.add :magick, :img, *(args + presets) do
14
+ PRESETS = presets
15
+ ARGS = args
16
+
17
+ class DoubleResizeError < RuntimeError
18
+ def initialize
19
+ "Both resize and @*x provided, this is not supported."
20
+ end
21
+ end
22
+
23
+ # ------------------------------------------------------------------------
24
+ # @see https://github.com/minimagick/minimagick#usage -- All but
25
+ # the boolean @ options are provided by Minimagick.
26
+ # ------------------------------------------------------------------------
27
+
28
+ def initialize(asset, opts, args)
29
+ @path = asset.filename
30
+ @opts = opts
31
+ @asset = asset
32
+ @args = args
33
+ end
34
+
35
+ # ------------------------------------------------------------------------
36
+
37
+ def process
38
+ img = MiniMagick::Image.open(@path)
39
+ methods = private_methods(true).select { |v| v =~ /\Amagick_/ }
40
+ if img.respond_to?(:combine_options)
41
+ then img.combine_options do |cmd|
42
+ methods.each do |method|
43
+ send(
44
+ method, img, cmd
45
+ )
46
+ end
47
+ end
48
+
49
+ else
50
+ methods.each do |method|
51
+ send(
52
+ method, img, img
53
+ )
54
+ end
55
+ end
56
+
57
+ img.write(
58
+ @path
59
+ )
60
+ ensure
61
+ img.destroy!
62
+ end
63
+
64
+ # ------------------------------------------------------------------------
65
+
66
+ private
67
+ def any_preset?(*keys)
68
+ @opts.keys.any? do |key|
69
+ keys.include?(key)
70
+ end
71
+ end
72
+
73
+ # ------------------------------------------------------------------------
74
+
75
+ private
76
+ def preset?
77
+ (@opts.keys - ARGS.map(&:to_sym)).any?
78
+ end
79
+
80
+ # ------------------------------------------------------------------------
81
+
82
+ private
83
+ def magick_quality(img, cmd)
84
+ if @opts.key?(:quality)
85
+ then cmd.quality @opts[:quality]
86
+ end
87
+ end
88
+
89
+ # ------------------------------------------------------------------------
90
+
91
+ private
92
+ def magick_resize(img, cmd)
93
+ raise DoubleResizeError if @opts.key?(:resize) && preset?
94
+ if @opts.key?(:resize)
95
+ then cmd.resize @opts[:resize]
96
+ end
97
+ end
98
+
99
+ # ------------------------------------------------------------------------
100
+
101
+ private
102
+ def magick_rotate(img, cmd)
103
+ if @opts.key?(:rotate)
104
+ then cmd.rotate @opts[:rotate]
105
+ end
106
+ end
107
+
108
+ # ------------------------------------------------------------------------
109
+
110
+ private
111
+ def magick_flip(img, cmd)
112
+ if @opts.key?(:flip)
113
+ then cmd.flip @opts[:flip]
114
+ end
115
+ end
116
+
117
+ # ------------------------------------------------------------------------
118
+
119
+ private
120
+ def magick_crop(img, cmd)
121
+ if @opts.key?(:crop)
122
+ then cmd.crop @opts[:crop]
123
+ end
124
+ end
125
+
126
+ # ------------------------------------------------------------------------
127
+
128
+ private
129
+ def magick_gravity(img, cmd)
130
+ if @opts.key?(:gravity)
131
+ then cmd.gravity @opts[:gravity]
132
+ end
133
+ end
134
+
135
+ # ------------------------------------------------------------------------
136
+ # I just want you to know, we don't even care if you do multiple
137
+ # resizes or try to, we don't attempt to even attempt to attempt to care
138
+ # we expect you to be logical and if you aren't we will comply.
139
+ # ------------------------------------------------------------------------
140
+
141
+ private
142
+ def magick_preset_resize(img, cmd)
143
+ return unless preset?
144
+ width, height = img.width * 4, img.height * 4 if any_preset?(:"4x", :quadruple)
145
+ width, height = img.width * 2, img.height * 2 if any_preset?(:"2x", :double)
146
+ width, height = img.width / 2, img.height / 2 if any_preset?(:"1/2", :half)
147
+ width, height = img.width / 3, img.height / 3 if any_preset?(:"1/3", :"one-third")
148
+ width, height = img.width / 4, img.height / 4 if any_preset?(:"1/4", :"one-fourth")
149
+ width, height = img.width / 3 * 2, img.height / 3 * 2 if any_preset?(:"2/3", :"two-thirds")
150
+ width, height = img.width / 4 * 2, img.height / 4 * 2 if any_preset?(:"2/4", :"two-fourths")
151
+ width, height = img.width / 4 * 3, img.height / 4 * 3 if any_preset?(:"3/4", :"three-fourths")
152
+ cmd.resize "#{width}x#{height}"
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,11 @@
1
+ # ----------------------------------------------------------------------------
2
+ # Frozen-string-literal: true
3
+ # Copyright: 2016-present - MIT License
4
+ # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
6
+
7
+ module Bunto
8
+ module Assets
9
+ VERSION="1.0.0.pre.alpha"
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ # ----------------------------------------------------------------------------
2
+ # Frozen-string-literal: true
3
+ # Copyright: 2016-present - MIT License
4
+ # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
6
+
7
+ require "sprockets"
8
+ require "bunto"
9
+
10
+ require_relative "assets/env"
11
+ require_relative "assets/version"
12
+ require_relative "assets/patches"
13
+ require_relative "assets/config"
14
+ require_relative "assets/cached"
15
+ require_relative "assets/hook"
16
+ require_relative "assets/logger"
17
+ require_relative "assets/hooks"
18
+ require_relative "assets/liquid"
19
+ require_relative "assets/addons/bootstrap"
20
+ require_relative "assets/addons/autoprefixer"
21
+ require_relative "assets/addons/font_awesome"
22
+ require_relative "assets/addons/javascript"
23
+ require_relative "assets/processors/liquid"
24
+ require_relative "assets/proxies/magick"
@@ -0,0 +1,7 @@
1
+ # ----------------------------------------------------------------------------
2
+ # Frozen-string-literal: true
3
+ # Copyright: 2016-present - MIT License
4
+ # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
6
+
7
+ require "bunto/assets"
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bunto-assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Jordon Bedwell
8
+ - Aleksey V Zapparov
9
+ - Zachary Bush
10
+ - Suriyaa Kudo
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2016-03-30 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: sprockets
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sprockets-helpers
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '1.2'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.2'
44
+ - !ruby/object:Gem::Dependency
45
+ name: fastimage
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '1.8'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.8'
58
+ - !ruby/object:Gem::Dependency
59
+ name: bunto
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '1.0'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: nokogiri
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: '1.6'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '1.6'
86
+ - !ruby/object:Gem::Dependency
87
+ name: luna-rspec-formatters
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '3.5'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '3.5'
100
+ - !ruby/object:Gem::Dependency
101
+ name: rspec
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '3.4'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '3.4'
114
+ description: |2
115
+ A Bunto plugin, that allows you to write javascript/css assets in
116
+ other languages such as CoffeeScript, Sass, Less and ERB, concatenate
117
+ them, respecting dependencies, minify and many more.
118
+ email:
119
+ - jordon@envygeeks.io
120
+ - ixti@member.fsf.org
121
+ - zach@zmbush.com
122
+ - SuriyaaKudoIsc@users.noreply.github.com
123
+ executables: []
124
+ extensions: []
125
+ extra_rdoc_files: []
126
+ files:
127
+ - Gemfile
128
+ - LICENSE
129
+ - README.md
130
+ - Rakefile
131
+ - lib/bunto-assets.rb
132
+ - lib/bunto/assets.rb
133
+ - lib/bunto/assets/addons/autoprefixer.rb
134
+ - lib/bunto/assets/addons/bootstrap.rb
135
+ - lib/bunto/assets/addons/font_awesome.rb
136
+ - lib/bunto/assets/addons/javascript.rb
137
+ - lib/bunto/assets/cached.rb
138
+ - lib/bunto/assets/config.rb
139
+ - lib/bunto/assets/env.rb
140
+ - lib/bunto/assets/hook.rb
141
+ - lib/bunto/assets/hooks.rb
142
+ - lib/bunto/assets/hooks/bunto/drops.rb
143
+ - lib/bunto/assets/hooks/bunto/setup.rb
144
+ - lib/bunto/assets/hooks/bunto/write.rb
145
+ - lib/bunto/assets/hooks/cache.rb
146
+ - lib/bunto/assets/hooks/compression.rb
147
+ - lib/bunto/assets/hooks/configuration.rb
148
+ - lib/bunto/assets/hooks/context.rb
149
+ - lib/bunto/assets/hooks/erb.rb
150
+ - lib/bunto/assets/hooks/helpers.rb
151
+ - lib/bunto/assets/hooks/logger.rb
152
+ - lib/bunto/assets/hooks/sources.rb
153
+ - lib/bunto/assets/hooks/sprockets.rb
154
+ - lib/bunto/assets/hooks/version.rb
155
+ - lib/bunto/assets/liquid.rb
156
+ - lib/bunto/assets/liquid/drop.rb
157
+ - lib/bunto/assets/liquid/filters.rb
158
+ - lib/bunto/assets/liquid/tag.rb
159
+ - lib/bunto/assets/liquid/tag/defaults.rb
160
+ - lib/bunto/assets/liquid/tag/defaults/image.rb
161
+ - lib/bunto/assets/liquid/tag/parser.rb
162
+ - lib/bunto/assets/liquid/tag/proxied_asset.rb
163
+ - lib/bunto/assets/liquid/tag/proxies.rb
164
+ - lib/bunto/assets/logger.rb
165
+ - lib/bunto/assets/patches.rb
166
+ - lib/bunto/assets/patches/bunto/cleaner.rb
167
+ - lib/bunto/assets/patches/bunto/site.rb
168
+ - lib/bunto/assets/patches/kernel.rb
169
+ - lib/bunto/assets/patches/sprockets/asset.rb
170
+ - lib/bunto/assets/processors/liquid.rb
171
+ - lib/bunto/assets/proxies/magick.rb
172
+ - lib/bunto/assets/version.rb
173
+ homepage: http://github.com/bunto/bunto-assets/
174
+ licenses:
175
+ - MIT
176
+ metadata: {}
177
+ post_install_message:
178
+ rdoc_options: []
179
+ require_paths:
180
+ - lib
181
+ required_ruby_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">"
189
+ - !ruby/object:Gem::Version
190
+ version: 1.3.1
191
+ requirements: []
192
+ rubyforge_project:
193
+ rubygems_version: 2.2.2
194
+ signing_key:
195
+ specification_version: 4
196
+ summary: Assets for Bunto
197
+ test_files: []