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.



82
83
84
85
86
87
# File 'lib/utopia/tags/gallery.rb', line 82

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



125
126
127
# File 'lib/utopia/tags/gallery.rb', line 125

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

Instance Attribute Details

#cache_rootObject (readonly)

Returns the value of attribute cache_root.



89
90
91
# File 'lib/utopia/tags/gallery.rb', line 89

def cache_root
  @cache_root
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



90
91
92
# File 'lib/utopia/tags/gallery.rb', line 90

def extensions
  @extensions
end

Class Method Details

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



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/utopia/tags/gallery.rb', line 96

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



92
93
94
# File 'lib/utopia/tags/gallery.rb', line 92

def original
	@original_path
end

#processed(process = nil) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/utopia/tags/gallery.rb', line 108

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



117
118
119
# File 'lib/utopia/tags/gallery.rb', line 117

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

#to_sObject



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

def to_s
	@original_path.to_s
end