placeimg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf5806a31cc34b808b94ecc38469e02e96f68eb7
4
+ data.tar.gz: 24eaa12ccf4ffda80c377eaecec98916d4acbb80
5
+ SHA512:
6
+ metadata.gz: 8fb196afaeb45247823f9e8596a30c25d0208aa9a17f254b600fbdd308fd5b88c94e016a627be145f02979f84a6c8495ccf11aa51c9b594bc301b29f6fb8c479
7
+ data.tar.gz: 2473f0be51197b15db467956ae0f98d15845e2a90f9d4e31a0385d3eb8529a45560141da7934c1b1c952a62c61c4e68df3cce65e862299b375dbae4283a7eae1
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ placeimg-*.gem
3
+ vendor
4
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,7 @@
1
+ module Placeimg
2
+ require "placeimg/view_helpers"
3
+ require "placeimg/version"
4
+ require 'placeimg/rails/railtie'
5
+ end
6
+
7
+
@@ -0,0 +1,8 @@
1
+ require 'placeimg'
2
+ require "rails"
3
+
4
+ class Railtie < Rails::Railtie
5
+ initializer "placeimg.helper" do |app|
6
+ ActionView::Base.send :include, Placeimg::ViewHelpers
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Placeimg
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ module Placeimg
2
+ module ViewHelpers
3
+
4
+ require 'base64' unless defined?(Base64)
5
+ require 'RMagick' unless defined?(Magick)
6
+ include Magick
7
+
8
+ def placeholder(details = nil)
9
+ details ||= {}
10
+ details[:bg] ||= '#ccc'
11
+ details[:fg] ||= '#777'
12
+ details[:h] ||= 250
13
+ details[:w] ||= 250
14
+ details[:class] ||= ""
15
+ details[:id] ||= ""
16
+
17
+ details[:h] = details[:h].to_i
18
+ details[:w] = details[:w].to_i
19
+
20
+ img = Image.new(details[:w], details[:h]) {
21
+ self.background_color = details[:bg]
22
+ self.format = "PNG"
23
+ }
24
+
25
+ if details[:h] > details[:w]
26
+ font_size = (details[:w] / 5).ceil
27
+ else
28
+ font_size = (details[:h] / 5).ceil
29
+ end
30
+
31
+ txt = Draw.new
32
+
33
+ img.annotate(txt, 0,0,0,0, "#{details[:w].to_s}x#{details[:h].to_s}") {
34
+ txt.gravity = Magick::CenterGravity
35
+ txt.pointsize = font_size
36
+ txt.fill = details[:fg]
37
+ }
38
+
39
+ data_uri = Base64.encode64(img.to_blob).gsub(/\n/, "")
40
+ output = '<img width="%s" height="%s" alt="placeholder" src="data:image/png;base64,%s" class="%s" id="%s">' % [details[:w].to_s, details[:h].to_s, data_uri, details[:class], details[:id]]
41
+ raw output
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "placeimg/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "placeimg"
7
+ s.version = Placeimg::VERSION
8
+ s.authors = ["Kelli Shaver"]
9
+ s.email = ["kelli@kellishaver.com"]
10
+ s.homepage = "https://github.com/kellishaver/placeimg"
11
+ s.summary = %q{Easily add placeholder images to your HTML.}
12
+ s.description = %q{PlaceImg lets you easily add placeholder images to your HTML by generating images with RMagick and serving them as data URLs via an easy to use helper method.}
13
+ s.license = "MIT"
14
+
15
+ s.rubyforge_project = "placeimg"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "rails", ">= 3.0"
21
+ s.add_dependency "rmagick"
22
+
23
+ end
@@ -0,0 +1,74 @@
1
+ PlaceImg
2
+ ====
3
+
4
+ PlaceImg is a simple gem that allows you to quickly and easily generate placeholder images via an easy to use view helper.
5
+
6
+ Placeholder images are generated via ImageMagick and are embedded in your views dynamically as data URLs. This means you won't need to clutter up image directories with junk files and you won't need to rely on an external source for placeholder iamges.
7
+
8
+ Installation
9
+ ----
10
+
11
+ Installing PlaceImg is as easy as running:
12
+
13
+ gem install placeimg
14
+
15
+ ###Requirements
16
+
17
+ PlaceImg requires you have the following on your system:
18
+
19
+ * ImageMagick
20
+ * Ghostscript
21
+
22
+ ###Gem Dependancies
23
+
24
+ PlaceImg has the following gem dependencies:
25
+
26
+ * Rails v3.0 or greater
27
+ * RMagick
28
+
29
+ Usage
30
+ ----
31
+
32
+ Using PlaceImg is simple. Just call the `placeholder` helper method anywhere inside your view files that you'd like to put a placeholder image.
33
+
34
+ The default placeholder is a 250x250px greyscale image.
35
+
36
+ <%= placeholder %>
37
+
38
+ ###Customizing the Placeholder
39
+
40
+ You can also customize your placeholder image by passing a variety of options to it:
41
+
42
+ * `h` - The height of the image in pixels
43
+ * `w` - The width of the image in pixels
44
+ * `bg` - The background color of the image, as a word (e.g. "red") or a hex code (e.g. '#f00' or '#ff0000')
45
+ * `fg` - The foreground (text) color of the image, as a word (e.g. "white") or a hex code (e.g. '#fff' or '#ffffff')
46
+ * `class` - A string of one or more class names to apply to the generated image tag
47
+ * `id` - An ID to apply to the generated image tag
48
+
49
+ For Example:
50
+
51
+ <%=
52
+ placeholder({
53
+ h: 90,
54
+ w: 760,
55
+ bg: '#777',
56
+ fg: '#fff',
57
+ class: 'banner',
58
+ id: 'top-sponsor'
59
+ })
60
+ %>
61
+
62
+ You can pass some, all, or no options to the helper. Below are the defaults:
63
+
64
+ * bg = #ccc
65
+ * fg = #777
66
+ * h = 250
67
+ * w = 250
68
+ * class = *empty string*
69
+ * id = *empty string*
70
+
71
+ ToDo
72
+ ----
73
+
74
+ * Tests - PlaceImg should be pretty fool-proof, but it could use a test or two.
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: placeimg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kelli Shaver
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rmagick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: PlaceImg lets you easily add placeholder images to your HTML by generating
42
+ images with RMagick and serving them as data URLs via an easy to use helper method.
43
+ email:
44
+ - kelli@kellishaver.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - lib/placeimg.rb
52
+ - lib/placeimg/rails/railtie.rb
53
+ - lib/placeimg/version.rb
54
+ - lib/placeimg/view_helpers.rb
55
+ - placeimg.gemspec
56
+ - readme.md
57
+ homepage: https://github.com/kellishaver/placeimg
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project: placeimg
77
+ rubygems_version: 2.0.3
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Easily add placeholder images to your HTML.
81
+ test_files: []