phil 0.9.3 → 0.9.4

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -3
  3. data/lib/phil.rb +40 -12
  4. data/lib/phil/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3668992d36762d34360443d60b52a7d95470ecf2
4
- data.tar.gz: f79137b76250fdca9aba3a7f3ee47d9323a4bc22
3
+ metadata.gz: e4e9e638d0090cd7da74ee87511da0d030e7663e
4
+ data.tar.gz: 0e8f9990581a6453d907b61e345ab4401d714ed8
5
5
  SHA512:
6
- metadata.gz: f5364b5be4065f4b3ffa0d768e049ef80cffadc33fc64df2f1e54db090ec82f0bd18a283e1ca7cc9826cbd2163c615bfd475e413f1082bbdf5f18a8a830aa401
7
- data.tar.gz: 727d7a711e09ccb853ac3856e1fd622637b1722896a3ee53ba20ab0d24d3a2727ca9749f9361891bd7451fd22c26308dda5931757f604990c8f2e4f248608e7f
6
+ metadata.gz: f7800c0b205c027686b072112b8d04229a94579ba933cc4425d33a889bb61661e3f7edcad8308f670e9d8f42e3ce88e756603eb2650d15ad839442b635a3c342
7
+ data.tar.gz: 644f7e825b4c8cdd9afae619374a60a1cb905df3f60474b11f6b9df825ecfa15b262720647787d1b548c32fd401434dda0e6eca448426520f5d501e12ba3a8ae
data/README.md CHANGED
@@ -50,13 +50,16 @@ Phil.markup "h1 p h2 ul p blockquote h5 h6"
50
50
 
51
51
  Generate a [placehold.it](http://placehold.it) image URL. Requires dimensions, but you can also request colors (in the format `#background/#foreground`) and containing text. Placehold.it doesn't play nice with some containing text characters so those are stripped out.
52
52
 
53
- You can pass arguments in any order – Phil is reasonably smart about figuring them out.
53
+ You can pass parameters in any order if you like – Phil is reasonably smart about figuring them out – or name them if you're feeling verbose.
54
54
 
55
55
  ```ruby
56
56
  Phil.image 200 # http://placehold.it/200
57
- Phil.image 200x400, #ff0000 # http://placehold.it/200x400/ff0000
58
- Phil.image 200x400, #ff0000/#00ff00 # http://placehold.it/200x400/ff0000/00ff00
57
+ Phil.image '200x400', '#ff0000' # http://placehold.it/200x400/ff0000
58
+ Phil.image '200x400', '#ff0000/#00ff00' # http://placehold.it/200x400/ff0000/00ff00
59
59
  Phil.image 'Jackie Jormp-Jomp?', 600 # http://placehold.it/600&text=Jackie+Jormp-Jomp
60
+
61
+ # or pass named parameters (you can use ranges for size here)
62
+ Phil.image(text: 'Pants', width: 300, height: (300..500), background: '#ff0000', foreground: '#0000ff')
60
63
  ```
61
64
 
62
65
  ### Lorem methods (all take ranges or numbers)
data/lib/phil.rb CHANGED
@@ -104,10 +104,8 @@ module Phil
104
104
  end
105
105
 
106
106
  def image(*arguments)
107
- opts = {}
108
- arguments.each do |arg|
109
- opts.merge! parse_image_argument(arg.to_s)
110
- end
107
+ opts = arguments.extract_options!
108
+ opts = format_image_argument_output(opts.merge! parse_image_arguments(arguments))
111
109
  opts[:size] && "http://placehold.it/#{opts[:size]}#{opts[:color]}#{opts[:text]}"
112
110
  end
113
111
 
@@ -141,15 +139,45 @@ module Phil
141
139
  "<#{name}>#{content}</#{name}>".html_safe
142
140
  end
143
141
 
144
- def parse_image_argument(argument)
145
- case argument
146
- when /^(#[a-f\d]{3,6}(\/(?=#))?){1,2}$/
147
- { :color => "/#{argument.gsub('#', '')}" }
148
- when /^\d*x?\d*?$/
149
- { :size => argument }
150
- else
151
- { :text => "&text=#{argument.gsub(/[^\d\w\!,\.;:-]+/, '+').gsub(/\+?$/, '')}" }
142
+ def convert_range(str)
143
+ range_ends = str.split('..')
144
+ str = range_ends[1] ? range_ends[0]..range_ends[1] : range_ends[0]
145
+ end
146
+
147
+ def parse_image_arguments(args)
148
+ output = {}
149
+ args.each do |arg|
150
+ case arg.to_s
151
+ when /^(#[a-f\d]{3,6}(\/(?=#))?){1,2}$/
152
+ output[:color] = arg
153
+ when /^([\d\.]*)x?([\d\.]*?)$/
154
+ output[:size] = arg
155
+ else
156
+ output[:text] = arg
157
+ end
158
+ end
159
+ output
160
+ end
161
+
162
+ def format_image_argument_output(args)
163
+
164
+ if !args[:color]
165
+ args[:color] = "#{args[:background]}#{args[:foreground]}"
166
+ end
167
+
168
+ if args[:width] && args[:height]
169
+ args[:size] = "#{Phil.pick(args[:width])}x#{Phil.pick(args[:height])}"
152
170
  end
171
+
172
+ args.each do |k, v|
173
+ case k
174
+ when /color/
175
+ args[k] = v.gsub(/\/?#/, '/')
176
+ when /text/
177
+ args[:text] = "&text=#{v.gsub(/[^\d\w\!,\.;:-]+/, '+').gsub(/\+?$/, '')}"
178
+ end
179
+ end
180
+
153
181
  end
154
182
 
155
183
  end
data/lib/phil/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Phil
2
- VERSION = '0.9.3'
2
+ VERSION = '0.9.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Daigle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-15 00:00:00.000000000 Z
11
+ date: 2013-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffaker