front_man 0.1.2 → 0.2.0

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: a10787fabe7a96368a32944056daadb118c1b33f
4
- data.tar.gz: 0ed139a951bb8a553b2400cf9b0cdfc84180bab9
3
+ metadata.gz: ef98b19bdac619ba344b5b35818dc457f8fc690d
4
+ data.tar.gz: 6b0c61e6c4e61f3b23408ba540c819704d5823a8
5
5
  SHA512:
6
- metadata.gz: f6c95800f8a0cb67927e54d1bead625ecf2e404b57b4b5b6135de775f1f8a3a3fcbcbdb0f88ac33af38f55cbbe0c9004b88188a9430c512e96a17afef3f323d7
7
- data.tar.gz: 2d211696e64cfe6077b3f66d77de38a8a75d5207336498853735e1e7a61617e22922b19d04456200264f22d83b9d52db78a86545d7936854cbe2ef278327b94c
6
+ metadata.gz: 8d1f92763814671313be2f697a17544b2cc09528ac3054f1d601133faea92e01a6ad397c777c160ecb37bbd1d7f116aafd007e4aefde598b9ff50d2e6fa4d2a7
7
+ data.tar.gz: 4733b4462fe61a80a59382826e19cf1825b7d081bfc635b41a4745ab4d0ad04b48391cc40d95fafcbd70aa97ffe44f8cf09721b9ae960659c0dc48375406df81
data/README.md CHANGED
@@ -90,13 +90,29 @@ Used to set `srcset` attribute on `img` tag.
90
90
  Example:
91
91
 
92
92
  ```ruby
93
- image_set_tag(item.image.medium, srcset: {
94
- item.image.thumb => '200w',
95
- item.image.medium => '600w',
96
- item.image.large => '800w'
97
- })
93
+ image_set_tag('http://placehold.it/1200x600',
94
+ srcset: {
95
+ 'http://placehold.it/300x150' => '300w',
96
+ 'http://placehold.it/600x300' => '600w',
97
+ 'http://placehold.it/1200x600' => '1200w'
98
+ }
99
+ )
98
100
  ```
99
101
 
102
+ If you would like to support lazy loading, in conjunction with [lazySizes](https://github.com/aFarkas/lazysizes), you just need to add the class `lazyload` as follows:
103
+
104
+ ```ruby
105
+ image_set_tag('http://placehold.it/1200x600',
106
+ srcset: {
107
+ 'http://placehold.it/300x150' => '300w',
108
+ 'http://placehold.it/600x300' => '600w',
109
+ 'http://placehold.it/1200x600' => '1200w'
110
+ },
111
+ class: 'lazyload'
112
+ )
113
+ ```
114
+ N.B. You would need to ensure the lazySizes script is installed for this to work
115
+
100
116
  ## Kudos
101
117
 
102
118
  The conventions laid out in the asset files here were based upon those discussed in the article below. Kudos to [@fat](https://github.com/fat).
@@ -26,8 +26,15 @@ module FrontMan
26
26
  srcset = srcset.join(', ')
27
27
 
28
28
  if options[:class].present? && options[:class].match(/\blazyload\b/)
29
+ options = options.dup
29
30
  options.delete(:srcset)
30
- options[:data] = { sizes: 'auto', srcset: srcset }
31
+ src = options[:src] || image_path(filename)
32
+ options.delete(:src)
33
+ options[:data] ||= {}
34
+ options[:data] = { sizes: 'auto', src: src, srcset: srcset }
35
+ .merge(options[:data])
36
+
37
+ return no_src_image_tag(filename, options)
31
38
  else
32
39
  options[:srcset] = srcset
33
40
  end
@@ -35,5 +42,22 @@ module FrontMan
35
42
 
36
43
  image_tag(filename, options)
37
44
  end
45
+
46
+ private
47
+
48
+ # extracted and modified from
49
+ # https://github.com/rails/rails/blob/878e42916db8a18f61333f315907480d7c48c040/actionview/lib/action_view/helpers/asset_tag_helper.rb#L208
50
+ def no_src_image_tag(source, options)
51
+ options = options.symbolize_keys
52
+
53
+ src = path_to_image(source)
54
+
55
+ unless src =~ /^(?:cid|data):/ || src.blank?
56
+ options[:alt] = options.fetch(:alt){ image_alt(src) }
57
+ end
58
+
59
+ options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
60
+ tag("img", options)
61
+ end
38
62
  end
39
63
  end
@@ -1,3 +1,3 @@
1
1
  module FrontMan
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: front_man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Fonic
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-01-20 00:00:00.000000000 Z
12
+ date: 2016-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport