amp_helper 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +35 -14
- data/amp_helper.gemspec +2 -0
- data/lib/amp_helper/amp_image_tag_helper.rb +28 -6
- data/lib/amp_helper/railtie.rb +1 -0
- data/lib/amp_helper/version.rb +1 -1
- metadata +30 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: fa951bbfd148bc82240773e639cbe2e49d9eff1d
         | 
| 4 | 
            +
              data.tar.gz: 8f64417bbae8acffbecc2834a5329db999f9f508
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9d9c548951e44e6451936402fac6640f4dfd0cf355ab351f6c27fd0826fe1b6997949fc15c3918531217b488b85db71b9565dee3df955bc177bb3f21198a57eb
         | 
| 7 | 
            +
              data.tar.gz: dcaed01087a475e2677f376c4b2c55201b6f5ab5e7bc4e265996137ac76e50ea793a5f9b85a25be2106d6f0a3ad241760e8546c0f12de370abc82e2e3ac4b266
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,8 +1,7 @@ | |
| 1 1 | 
             
            # AmpHelper
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            -
            TODO: Delete this and the text above, and describe your gem
         | 
| 3 | 
            +
            AmpHelper helps you generate html tags for AMP.
         | 
| 4 | 
            +
            To know AmpHelper ability, just look Usage section.
         | 
| 6 5 |  | 
| 7 6 | 
             
            ## Installation
         | 
| 8 7 |  | 
| @@ -25,24 +24,46 @@ Or install it yourself as: | |
| 25 24 |  | 
| 26 25 | 
             
            ### Helpers
         | 
| 27 26 |  | 
| 28 | 
            -
            #### amp_image_tag(source, options)
         | 
| 27 | 
            +
            #### amp_image_tag(source, options = {})
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            ##### String Source
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  $ amp_image_tag('http://placehold.it/350x150', width: 20, height: 20)
         | 
| 32 | 
            +
                  #=> '<amp-img alt="350x150" height="20" src="http://placehold.it/350x150" width="20" /></amp-img>'
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  $ amp_image_tag('http://placehold.it/350x150', size: '20x20')
         | 
| 35 | 
            +
                  #=> '<amp-img alt="350x150" height="20" src="http://placehold.it/350x150" width="20" /></amp-img>'
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  $ amp_image_tag('http://placehold.it/350x150')
         | 
| 38 | 
            +
                  #=> '<amp-img alt="350x150" height="150" src="http://placehold.it/350x150" width="350" /></amp-img>'
         | 
| 29 39 |  | 
| 30 | 
            -
            #####  | 
| 40 | 
            +
            ##### Carrierwave Source
         | 
| 31 41 |  | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 42 | 
            +
                  $ amp_image_tag(ThumbUploader.new.square)
         | 
| 43 | 
            +
                  #=> '<amp-img alt="Square 350x150" height="20" src="http://placehold.it/square_350x150" width="20" /></amp-img>'
         | 
| 34 44 |  | 
| 35 | 
            -
            #####  | 
| 45 | 
            +
            ##### Retina
         | 
| 36 46 |  | 
| 37 | 
            -
             | 
| 47 | 
            +
                  $ amp_image_tag('http://placehold.it/350x150', srcset: 'http://placehold.it/700x300', size: '20x20')
         | 
| 48 | 
            +
                  #=> '<amp-img alt="350x150" height="20" src="http://placehold.it/350x150" srcset="http://placehold.it/700x300" width="20" /></amp-img>'
         | 
| 38 49 |  | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 50 | 
            +
                  $ amp_image_tag(ThumbUploader.new.square, format_2x: '%s_2x')
         | 
| 51 | 
            +
                  #=> '<amp-img alt="Square 350x150" height="20" src="http://placehold.it/square_350x150" srcset="http://placehold.it/square_2x_350x150" width="20" /></amp-img>'
         | 
| 41 52 |  | 
| 42 | 
            -
            #####  | 
| 53 | 
            +
            ##### ThumbUploader Sample
         | 
| 43 54 |  | 
| 44 | 
            -
                 | 
| 45 | 
            -
             | 
| 55 | 
            +
                class ThumbUploader < CarrierWave::Uploader::Base
         | 
| 56 | 
            +
                  storage :file
         | 
| 57 | 
            +
                  version :square do
         | 
| 58 | 
            +
                    process resize_to_fill: [20, 20]
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
                  version :square_2x do
         | 
| 61 | 
            +
                    process resize_to_fill: [40, 40]
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
                  def default_url(*args)
         | 
| 64 | 
            +
                    'http://placehold.it/' + [version_name, '350x150'].compact.join('_')
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
                end
         | 
| 46 67 |  | 
| 47 68 | 
             
            ## Development
         | 
| 48 69 |  | 
    
        data/amp_helper.gemspec
    CHANGED
    
    | @@ -23,6 +23,8 @@ Gem::Specification.new do |spec| | |
| 23 23 | 
             
              spec.add_development_dependency 'bundler', '~> 1.13'
         | 
| 24 24 | 
             
              spec.add_development_dependency 'rake', '~> 10.0'
         | 
| 25 25 | 
             
              spec.add_development_dependency 'rspec-rails', '~> 3.0'
         | 
| 26 | 
            +
              spec.add_development_dependency 'pry', '~> 0.10.4'
         | 
| 26 27 | 
             
              spec.add_dependency 'rails', '~> 4.1.8'
         | 
| 27 28 | 
             
              spec.add_dependency 'fastimage', '~> 2.0.1'
         | 
| 29 | 
            +
              spec.add_dependency 'carrierwave', '~> 1.0.0.rc'
         | 
| 28 30 | 
             
            end
         | 
| @@ -1,10 +1,32 @@ | |
| 1 1 | 
             
            module AmpImageTagHelper
         | 
| 2 2 | 
             
              def amp_image_tag(source, opts = {})
         | 
| 3 | 
            -
                has_dimensions =  | 
| 4 | 
            -
                 | 
| 5 | 
            -
                 | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 3 | 
            +
                has_dimensions = (opts[:width] && opts[:height]) || opts[:size]
         | 
| 4 | 
            +
                set_dimensions(source, opts) if !has_dimensions
         | 
| 5 | 
            +
                set_scrset(source, opts)
         | 
| 6 | 
            +
                image_tag_to_amp(image_tag(source, opts))
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              private
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              def image_tag_to_amp(img_tag)
         | 
| 12 | 
            +
                img_tag.gsub(/^<img/, '<amp-img').gsub(/>$/, '></amp-img>').html_safe
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def set_dimensions(source, opts)
         | 
| 16 | 
            +
                if source.kind_of?(CarrierWave::Uploader::Base) &&
         | 
| 17 | 
            +
                   !source.class.processors.empty?
         | 
| 18 | 
            +
                  opts[:width], opts[:height] = source.class.processors[0][1]
         | 
| 19 | 
            +
                else
         | 
| 20 | 
            +
                  opts[:width], opts[:height] = FastImage.size(source.to_s)
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              def set_scrset(source, opts)
         | 
| 25 | 
            +
                if source.kind_of?(CarrierWave::Uploader::Base) &&
         | 
| 26 | 
            +
                   !source.class.processors.empty? &&
         | 
| 27 | 
            +
                   format_2x = opts.delete(:format_2x)
         | 
| 28 | 
            +
                  name_2x = format_2x % source.version_name
         | 
| 29 | 
            +
                  opts[:srcset] = source.parent_version.send(name_2x).url
         | 
| 30 | 
            +
                end
         | 
| 9 31 | 
             
              end
         | 
| 10 32 | 
             
            end
         | 
    
        data/lib/amp_helper/railtie.rb
    CHANGED
    
    
    
        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.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Awjecc
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2017-01-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -52,6 +52,20 @@ dependencies: | |
| 52 52 | 
             
                - - "~>"
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: '3.0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: pry
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - "~>"
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: 0.10.4
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - "~>"
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: 0.10.4
         | 
| 55 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 70 | 
             
              name: rails
         | 
| 57 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -80,6 +94,20 @@ dependencies: | |
| 80 94 | 
             
                - - "~>"
         | 
| 81 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 96 | 
             
                    version: 2.0.1
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: carrierwave
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - "~>"
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: 1.0.0.rc
         | 
| 104 | 
            +
              type: :runtime
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - "~>"
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: 1.0.0.rc
         | 
| 83 111 | 
             
            description: 
         | 
| 84 112 | 
             
            email:
         | 
| 85 113 | 
             
            - awjecc@gmail.com
         |