amp_helper 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -13
- data/lib/amp_helper/amp_image_tag_helper.rb +1 -1
- data/lib/amp_helper/configuration.rb +18 -0
- data/lib/amp_helper/generator.rb +15 -0
- data/lib/amp_helper/railtie.rb +5 -0
- data/lib/amp_helper/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa11cbafeee50553da50fbd031a4acc8140c4082
|
4
|
+
data.tar.gz: eedd79a377bd27f516637077fa19e1431e3bd316
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f53a9fce0fc324ef1d59a483b53f8c05d7f21a34c1399930caf0f95bb9cd2e91ab3c1215ea1a96508ffd8dbef46925f99197f16e100c3ad7dcfa17f6a321a91
|
7
|
+
data.tar.gz: 74e6c8b5d088cead17342736d83a705afeb047afc77b03c485b72004d6d49270f6086b1a6036f78ff31b2d0fa0dad2f5e652a2287ab818f3e08530135e62adc2
|
data/README.md
CHANGED
@@ -14,19 +14,13 @@ gem 'amp_helper'
|
|
14
14
|
And then execute:
|
15
15
|
|
16
16
|
$ bundle
|
17
|
+
$ rails g amp_helper
|
17
18
|
|
18
|
-
|
19
|
+
## Helpers usage
|
19
20
|
|
20
|
-
|
21
|
+
### amp_image_tag(source, options = {})
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
### Helpers
|
26
|
-
|
27
|
-
#### amp_image_tag(source, options = {})
|
28
|
-
|
29
|
-
##### String Source
|
23
|
+
#### String Source
|
30
24
|
|
31
25
|
$ amp_image_tag('http://placehold.it/350x150', width: 20, height: 20)
|
32
26
|
#=> '<amp-img alt="350x150" height="20" src="http://placehold.it/350x150" width="20" /></amp-img>'
|
@@ -37,12 +31,12 @@ Or install it yourself as:
|
|
37
31
|
$ amp_image_tag('http://placehold.it/350x150')
|
38
32
|
#=> '<amp-img alt="350x150" height="150" src="http://placehold.it/350x150" width="350" /></amp-img>'
|
39
33
|
|
40
|
-
|
34
|
+
#### Carrierwave Source
|
41
35
|
|
42
36
|
$ amp_image_tag(ThumbUploader.new.square)
|
43
37
|
#=> '<amp-img alt="Square 350x150" height="20" src="http://placehold.it/square_350x150" width="20" /></amp-img>'
|
44
38
|
|
45
|
-
|
39
|
+
#### Retina
|
46
40
|
|
47
41
|
$ amp_image_tag('http://placehold.it/350x150', srcset: 'http://placehold.it/700x300 2x', size: '20x20')
|
48
42
|
#=> '<amp-img alt="350x150" height="20" src="http://placehold.it/350x150" srcset="http://placehold.it/700x300 2x" width="20" /></amp-img>'
|
@@ -50,7 +44,8 @@ Or install it yourself as:
|
|
50
44
|
$ amp_image_tag(ThumbUploader.new.square, format_2x: '%s_2x')
|
51
45
|
#=> '<amp-img alt="Square 350x150" height="20" src="http://placehold.it/square_350x150" srcset="http://placehold.it/square_2x_350x150 2x" width="20" /></amp-img>'
|
52
46
|
|
53
|
-
|
47
|
+
|
48
|
+
##### Example of CarrierWave::Uploader versions.
|
54
49
|
|
55
50
|
class ThumbUploader < CarrierWave::Uploader::Base
|
56
51
|
storage :file
|
@@ -65,6 +60,17 @@ Or install it yourself as:
|
|
65
60
|
end
|
66
61
|
end
|
67
62
|
|
63
|
+
## Configure
|
64
|
+
|
65
|
+
### Configure ratina version name format For CarrierWave::Uploader
|
66
|
+
|
67
|
+
config/initializers/amp_helper.rb
|
68
|
+
|
69
|
+
AmpHelper.configure do |config|
|
70
|
+
# Configure ratina version name format For CarrierWave::Uploader
|
71
|
+
# config.format_2x = '%s_2x'
|
72
|
+
end
|
73
|
+
|
68
74
|
## Development
|
69
75
|
|
70
76
|
bundle exec rspec
|
@@ -24,7 +24,7 @@ module AmpImageTagHelper
|
|
24
24
|
def set_scrset(source, opts)
|
25
25
|
if source.kind_of?(CarrierWave::Uploader::Base) &&
|
26
26
|
!source.class.processors.empty? &&
|
27
|
-
format_2x = opts.delete(:format_2x)
|
27
|
+
format_2x = (opts.delete(:format_2x) || AmpHelper.configuration.format_2x)
|
28
28
|
name_2x = format_2x % source.version_name
|
29
29
|
opts[:srcset] = "#{source.parent_version.send(name_2x).url} 2x"
|
30
30
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AmpHelper
|
2
|
+
class << self
|
3
|
+
attr_accessor :configuration
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configure
|
7
|
+
self.configuration ||= Configuration.new
|
8
|
+
yield(configuration)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Configuration
|
12
|
+
attr_accessor :format_2x
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@format_2x = nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module AmpHelper
|
2
|
+
class AmpHelperGenerator < Rails::Generators::Base
|
3
|
+
desc 'Initialize AmpHelper'
|
4
|
+
def create_initializer_file
|
5
|
+
initializer 'amp_helper.rb' do
|
6
|
+
<<-FILE.strip_heredoc
|
7
|
+
AmpHelper.configure do |config|
|
8
|
+
# Configure ratina version name format For CarrierWave::Uploader
|
9
|
+
# config.format_2x = '%s_2x'
|
10
|
+
end
|
11
|
+
FILE
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/amp_helper/railtie.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'carrierwave'
|
2
2
|
require 'fastimage'
|
3
|
+
require 'amp_helper/configuration'
|
3
4
|
require 'amp_helper/amp_image_tag_helper'
|
4
5
|
|
5
6
|
module AmpHelper
|
@@ -7,5 +8,9 @@ module AmpHelper
|
|
7
8
|
initializer 'image_tag.helper' do |app|
|
8
9
|
ActionView::Base.send :include, AmpImageTagHelper
|
9
10
|
end
|
11
|
+
|
12
|
+
generators do
|
13
|
+
require 'amp_helper/generator.rb'
|
14
|
+
end
|
10
15
|
end
|
11
16
|
end
|
data/lib/amp_helper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amp_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Awjecc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,6 +128,8 @@ files:
|
|
128
128
|
- bin/setup
|
129
129
|
- lib/amp_helper.rb
|
130
130
|
- lib/amp_helper/amp_image_tag_helper.rb
|
131
|
+
- lib/amp_helper/configuration.rb
|
132
|
+
- lib/amp_helper/generator.rb
|
131
133
|
- lib/amp_helper/railtie.rb
|
132
134
|
- lib/amp_helper/version.rb
|
133
135
|
homepage: http://awjecc.com
|