define_images 0.1.1
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +36 -0
- data/Rakefile +2 -0
- data/define_images.gemspec +21 -0
- data/init.rb +1 -0
- data/lib/define_images.rb +2 -0
- data/lib/define_images/helpers.rb +14 -0
- data/lib/define_images/version.rb +3 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# define_images
|
2
|
+
|
3
|
+
version 0.1.1
|
4
|
+
Robin Brouwer
|
5
|
+
45north
|
6
|
+
|
7
|
+
Sometimes you need to use the same image multiple times on your website.
|
8
|
+
You need to create an image_tag for each image with all the attributes you want added to the image.
|
9
|
+
|
10
|
+
For example:
|
11
|
+
|
12
|
+
<%= image_tag "rails.png", :alt => "Ruby on Rails logo", :title => "Ruby on Rails logo", :width => 50, :height => 64 %>
|
13
|
+
|
14
|
+
But when you add this image_tag inside different views you're not actually doing it the DRY way.
|
15
|
+
That's why I created this plugin. You can define your images once and then call them easily within a view.
|
16
|
+
|
17
|
+
This is how define_images works:
|
18
|
+
|
19
|
+
# Inside your ApplicationHelper
|
20
|
+
module ApplicationHelper
|
21
|
+
define_image :rails, "rails.png", :alt => "Ruby on Rails logo", :width => 50, :height => 64, :title => "Ruby on Rails logo"
|
22
|
+
end
|
23
|
+
|
24
|
+
First you pass the name of the image (:rails), then the path to the image ("rails.png") and after the path you can give all the arguments.
|
25
|
+
Showing this image is also quite easy:
|
26
|
+
|
27
|
+
# Inside your views:
|
28
|
+
<%= img(:rails) %>
|
29
|
+
|
30
|
+
That's it! Now your image is defined only once and can be called easily with the 'img' helper.
|
31
|
+
|
32
|
+
To install the gem you can put the following inside your Gemfile.
|
33
|
+
|
34
|
+
gem "define_images"
|
35
|
+
|
36
|
+
When you have suggestions and/or improvements, please contact me: robin@45north.nl.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "define_images/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "define_images"
|
7
|
+
s.version = DefineImages::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Robin Brouwer"]
|
10
|
+
s.email = ["robin@45north.nl"]
|
11
|
+
s.homepage = "http://www.45north.nl"
|
12
|
+
s.summary = %q{Define images for your views.}
|
13
|
+
s.description = %q{Easily define images only once and show them in your views in a DRY manner.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "nowarning"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'define_images'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DefineImages
|
2
|
+
module Helpers
|
3
|
+
def define_image key, path, *args
|
4
|
+
@@defined_images ||= {}
|
5
|
+
@@defined_images[key] = { :path => path, :args => args.extract_options! }
|
6
|
+
nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def img key
|
10
|
+
@@defined_images ||= {}
|
11
|
+
image_tag(@@defined_images[key][:path], @@defined_images[key][:args]) if @@defined_images.has_key?(key)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: define_images
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Robin Brouwer
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-02 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Easily define images only once and show them in your views in a DRY manner.
|
22
|
+
email:
|
23
|
+
- robin@45north.nl
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- README.markdown
|
34
|
+
- Rakefile
|
35
|
+
- define_images.gemspec
|
36
|
+
- init.rb
|
37
|
+
- lib/define_images.rb
|
38
|
+
- lib/define_images/helpers.rb
|
39
|
+
- lib/define_images/version.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://www.45north.nl
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: nowarning
|
66
|
+
rubygems_version: 1.3.6
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Define images for your views.
|
70
|
+
test_files: []
|
71
|
+
|