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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57f84112724f8febeb83e9564db3fdc6b77f0398
4
- data.tar.gz: 5877521f758d8d35fa176a409598ea560d336481
3
+ metadata.gz: fa11cbafeee50553da50fbd031a4acc8140c4082
4
+ data.tar.gz: eedd79a377bd27f516637077fa19e1431e3bd316
5
5
  SHA512:
6
- metadata.gz: 1ae311480df691c349b620478324bfd79cb325090b9cc263e5320d2f69cf32115960a7851593893bf52f0ada56279942422cc591d5c912722dea7f5866b3d867
7
- data.tar.gz: 0f403c347c25607beeb288e35710d0b3c6cb44eec231df70511d3045e591905ab26a719550989e4c92f231ec9c2aa93919e9127013a55f622eb40a9614182cc3
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
- Or install it yourself as:
19
+ ## Helpers usage
19
20
 
20
- $ gem install amp_helper
21
+ ### amp_image_tag(source, options = {})
21
22
 
22
- ## Usage
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
- ##### Carrierwave Source
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
- ##### Retina
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
- ##### ThumbUploader Sample
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module AmpHelper
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
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.2
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-19 00:00:00.000000000 Z
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