Class: Utopia::Tags::Gallery::ImagePath

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/tags/gallery.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_path) ⇒ ImagePath

Returns a new instance of ImagePath.



96
97
98
99
100
101
# File 'lib/utopia/tags/gallery.rb', line 96

def initialize(original_path)
	@original_path = original_path
	@cache_root = @original_path.dirname + CACHE_DIR
	
	@extensions = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



139
140
141
# File 'lib/utopia/tags/gallery.rb', line 139

def method_missing(name, *args)
	return processed(name.to_s)
end

Instance Attribute Details

#cache_rootObject (readonly)

Returns the value of attribute cache_root.



103
104
105
# File 'lib/utopia/tags/gallery.rb', line 103

def cache_root
  @cache_root
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



104
105
106
# File 'lib/utopia/tags/gallery.rb', line 104

def extensions
  @extensions
end

Class Method Details

.append_suffix(name, suffix, extension = nil) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/utopia/tags/gallery.rb', line 110

def self.append_suffix(name, suffix, extension = nil)
	components = name.split(".")
	
	components.insert(-2, suffix)
	
	if (extension)
		components[-1] = extension
	end
	
	return components.join(".")
end

Instance Method Details

#originalObject



106
107
108
# File 'lib/utopia/tags/gallery.rb', line 106

def original
	@original_path
end

#processed(process = nil) ⇒ Object



122
123
124
125
126
127
128
129
# File 'lib/utopia/tags/gallery.rb', line 122

def processed(process = nil)
	if process
		name = @original_path.basename
		return cache_root + ImagePath.append_suffix(name, process.to_s, @extensions[process.to_sym])
	else
		return @original_path
	end
end

#to_html(process = nil) ⇒ Object



131
132
133
# File 'lib/utopia/tags/gallery.rb', line 131

def to_html(process = nil)
	Tag.new("img", {"src" => path(process)}).to_html
end

#to_sObject



135
136
137
# File 'lib/utopia/tags/gallery.rb', line 135

def to_s
	@original_path.to_s
end