phil 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/phil.rb +40 -12
- data/lib/phil/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4e9e638d0090cd7da74ee87511da0d030e7663e
|
4
|
+
data.tar.gz: 0e8f9990581a6453d907b61e345ab4401d714ed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
58
|
-
Phil.image 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
|
-
|
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
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
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
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.
|
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-
|
11
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffaker
|