Module AutoImageTag
In: lib/auto_image_tag.rb

image_tag を置き換える。 image_tagsrc 属性に指定されているファイルが存在しない場合に、 代替として文字列を埋め込む。

Methods

Constants

IMAGES = {}

Public Class methods

[Source]

    # File lib/auto_image_tag.rb, line 22
22:     def self.reload
23:       IMAGES.clear
24:       info = {}.freeze
25:       Dir.glob(File.join(RAILS_ROOT, "public/images/*.*")).map do |img|
26:         IMAGES[File.basename(img)] = info
27:       end
28:     end

[Source]

    # File lib/auto_image_tag.rb, line 10
10:     def self.reload
11:       IMAGES.clear
12:       Dir.glob(File.join(RAILS_ROOT, "public/images/*.*")).map do |img|
13:         info = {}
14:         open(img, "rb") do |f|
15:           info[:size] = ImageSize.new(f.read).size.join("x")
16:         end
17:         info.delete(:size) if info[:size] == "x"
18:         IMAGES[File.basename(img)] = info.freeze
19:       end
20:     end

Public Instance methods

image_submit_tag を置き換える。

[Source]

    # File lib/auto_image_tag.rb, line 44
44:   def image_submit_tag(source, options={})
45:     info = IMAGES[source]
46:     if info
47:       super(source, info.dup.update(options))
48:     else
49:       submit_tag(options[:alt] || File.basename(source))
50:     end
51:   end

image_tag を置き換える。

[Source]

    # File lib/auto_image_tag.rb, line 34
34:   def image_tag(source, options={})
35:     info = IMAGES[source]
36:     if info
37:       super(source, info.dup.update(options))
38:     else
39:       h(options[:alt] || File.basename(source))
40:     end
41:   end

[Validate]