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.



112
113
114
115
116
117
# File 'lib/utopia/tags/gallery.rb', line 112

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



155
156
157
# File 'lib/utopia/tags/gallery.rb', line 155

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

Instance Attribute Details

#cache_rootObject (readonly)

Returns the value of attribute cache_root.



119
120
121
# File 'lib/utopia/tags/gallery.rb', line 119

def cache_root
  @cache_root
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



120
121
122
# File 'lib/utopia/tags/gallery.rb', line 120

def extensions
  @extensions
end

Class Method Details

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



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/utopia/tags/gallery.rb', line 126

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



122
123
124
# File 'lib/utopia/tags/gallery.rb', line 122

def original
	@original_path
end

#processed(process = nil) ⇒ Object



138
139
140
141
142
143
144
145
# File 'lib/utopia/tags/gallery.rb', line 138

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



147
148
149
# File 'lib/utopia/tags/gallery.rb', line 147

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

#to_sObject



151
152
153
# File 'lib/utopia/tags/gallery.rb', line 151

def to_s
	@original_path.to_s
end