img_return 1.0.1 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/img_return.rb +29 -10
- 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: a0bab96b231abdf2547e20b0fc40b22252960bf5
|
4
|
+
data.tar.gz: 9c8445b808d5ea2d62a763e8ff1d0a9920713cd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 065471630407a7a0fddeb979e3e2e72441f36b5bdb6323215853f203aaedc83dabc343d9f51150bfc749d611868f2014cce1201578e589351f96a712f5d069c2
|
7
|
+
data.tar.gz: 579cac646baf6801c16d8728ec3c06cf2f5e158dba4ff012e85875b36ab7bf3d17c243dd97ee01fbd9bb8a1dc7f67c042163c3bc46b0efbfb07041fd823d7bad
|
data/lib/img_return.rb
CHANGED
@@ -1,18 +1,28 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
|
3
3
|
module Return_Img
|
4
|
+
Colors = {:AliceBlue => "#F0F8FF", :AntiqueWhite => "#FAEBD7", :Aqua => "#00FFFF", :Aquamarine => "#7FFFD4", :Azure => "#F0FFFF", :Beige => "#F5F5DC", :Bisque => "#FFE4C4", :Black => "#000000", :BlanchedAlmond => "#FFEBCD", :Blue => "#0000FF", :BlueViolet => "#8A2BE2", :Brown => "#A52A2A", :BurlyWood => "#DEB887", :CadetBlue => "#5F9EA0", :Chartreuse => "#7FFF00", :Chocolate => "#D2691E", :Coral => "#FF7F50", :CornflowerBlue => "#6495ED", :Cornsilk => "#FFF8DC", :Crimson => "#DC143C", :Cyan => "#00FFFF", :DarkBlue => "#00008B"}
|
4
5
|
# Gets array and returns one random element from the array.
|
5
|
-
def self.
|
6
|
+
def self.return_random(arry)
|
7
|
+
raise TypeError, "Argument must be an array." if arry.class != Array
|
6
8
|
random_img = Random.new
|
7
|
-
ri = random_img.rand(0..
|
8
|
-
|
9
|
-
@return_background_img =
|
9
|
+
ri = random_img.rand(0..arry.size)
|
10
|
+
arry.each_index{|ei|
|
11
|
+
@return_background_img = arry[ri] if ei == ri
|
10
12
|
}
|
11
13
|
return @return_background_img
|
12
14
|
end
|
15
|
+
def self.write_css_file(path, css_code)
|
16
|
+
raise TypeError, "First argument 'path' must be a String." if path.class != String
|
17
|
+
raise TypeError, "Second argument 'css_code' must be a String." if css_code.class != String
|
18
|
+
File.open("#{path}.css", 'w'){|fp|
|
19
|
+
fp.puts(css_code)
|
20
|
+
}
|
21
|
+
return css_code
|
22
|
+
end
|
13
23
|
class Background_Image
|
14
|
-
# Returns a list of images in the specified directory.
|
15
24
|
def list_images(dir)
|
25
|
+
raise TypeError, "dir must be a String." if dir.class != String
|
16
26
|
possible_background_images = []
|
17
27
|
if dir == "."
|
18
28
|
FileUtils.cd("app/assets/images") do
|
@@ -29,17 +39,26 @@ module Return_Img
|
|
29
39
|
end
|
30
40
|
return possible_background_images
|
31
41
|
end
|
32
|
-
# Writes a css file to read in via erb with a different result each refresh.
|
33
|
-
# bg_img the css url and css_filename is the name of the css file you want to write.
|
34
42
|
def write_css_file(bg_img, css_filename)
|
43
|
+
raise TypeError, "First argument 'bg_img' must be a String." if bg_img.class != String
|
44
|
+
raise TypeError, "Second argument 'css_filename' must be a String." if css_filename.class != String
|
35
45
|
background_css_code = "body {
|
36
46
|
background-image: url('#{bg_img}');
|
37
47
|
background-repeat:no-repeat;
|
38
48
|
background-size:cover;
|
39
49
|
}"
|
40
|
-
|
41
|
-
|
42
|
-
|
50
|
+
Return_Img.write_css_file("app/assets/stylesheets/#{css_filename}", "#{background_css_code}")
|
51
|
+
return background_css_code
|
52
|
+
end
|
53
|
+
def self.render_color_style(element, style, css_filename)
|
54
|
+
raise TypeError, "First argument 'element' must be a String." if element.class != String
|
55
|
+
raise TypeError, "Second argument 'style' must be a String." if style.class != String
|
56
|
+
raise TypeError, "Third argument 'css_filename' must be a String." if css_filename.class != String
|
57
|
+
css_color_code = "#{element} {
|
58
|
+
background-color: #{style};
|
59
|
+
}"
|
60
|
+
Return_Img.write_css_file("app/assets/stylesheets/#{css_filename}", "#{css_color_code}")
|
61
|
+
return css_color_code
|
43
62
|
end
|
44
63
|
end
|
45
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: img_return
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ralph Desir
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A gem made for returning picture files for rails views.
|
14
14
|
email: battleroundscool@gmail.com
|