img_return 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/img_return.rb +45 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ad6d6d46ef1dc3849f72d8979128bd92fd48a41
4
+ data.tar.gz: e533e57c216122008f330e1d6644b27c6fa95bff
5
+ SHA512:
6
+ metadata.gz: cc15ce4e3f15057a36474aa5802b90b6f46c554bf8428b260de01c9217cf286a43279c683ff26497b4ae1d7664ca00fcdc7ebb376b8ca38295d0314992471ec4
7
+ data.tar.gz: 16256ab4a9476b7a16fa6524b17ee54c33bcc8445c0fb2ffd3d7589fa9f196728f14e67e8301f7350a29832652142e8d23f2f56895802ea683195fc5499a111a
data/lib/img_return.rb ADDED
@@ -0,0 +1,45 @@
1
+ require "fileutils"
2
+
3
+ module Return_Img
4
+ # Gets array and returns one random element from the array.
5
+ def self.return_random_img(arg)
6
+ random_img = Random.new
7
+ ri = random_img.rand(0..arg.size)
8
+ arg.each_index{|ei|
9
+ @return_background_img = arg[ri] if ei == ri
10
+ }
11
+ return @return_background_img
12
+ end
13
+ class Background_Image
14
+ # Returns a list of images in the specified directory.
15
+ def list_images(dir)
16
+ possible_background_images = []
17
+ if dir == "."
18
+ FileUtils.cd("app/assets/images") do
19
+ Dir.entries(".").each{|en|
20
+ possible_background_images.push(en) if File.extname(en) == ".png" || File.extname(en) == ".jpg" || File.extname(en) == ".tiff"
21
+ }
22
+ end
23
+ else
24
+ FileUtils.cd("app/assets/images/#{dir}") do
25
+ Dir.entries(".").each{|en|
26
+ possible_background_images.push(en) if File.extname(en) == ".png" || File.extname(en) == ".jpg" || File.extname(en) == ".tiff"
27
+ }
28
+ end
29
+ end
30
+ return possible_background_images
31
+ 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
+ def write_css_file(bg_img, css_filename)
35
+ background_css_code = "body {
36
+ background-image: url('#{bg_img}');
37
+ background-repeat:no-repeat;
38
+ background-size:cover;
39
+ }"
40
+ File.open("app/assets/stylesheets/#{css_file_path}.css", 'w'){|fp|
41
+ fp.puts(background_css_code)
42
+ }
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: img_return
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ralph Desir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem made for returning picture files for rails views.
14
+ email: battleroundscool@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/img_return.rb
20
+ homepage: https://github.com/Mav7/img_return
21
+ licenses:
22
+ - GPLv2
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.8
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Image return.
44
+ test_files: []