Class: Pupu::Pupu
- Inherits:
-
Object
- Object
- Pupu::Pupu
- Defined in:
- lib/pupu/pupu.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
- .[](plugin, params = Hash.new) ⇒ Object
-
.all ⇒ Object
TODO: return Pupu object, not string.
- .root ⇒ Object
-
.root=(directory) ⇒ Object
TODO: reflect changes on root method.
-
.root_path ⇒ Object
same as root, but doesn’t raise any exception.
Instance Method Summary collapse
- #copy_initializers ⇒ Object
- #file(path, root = self.root) ⇒ Object
- #image(basename) ⇒ Object
-
#initialize(name, params = Hash.new) ⇒ Pupu
constructor
A new instance of Pupu.
- #initializer(type = :all) ⇒ Object
- #javascript(basename) ⇒ Object
- #metadata ⇒ Object
- #root ⇒ Object
- #soft_file(path, root = self.root) ⇒ Object
- #stylesheet(basename) ⇒ Object
- #uninstall ⇒ Object
Constructor Details
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
109 110 111 |
# File 'lib/pupu/pupu.rb', line 109 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
109 110 111 |
# File 'lib/pupu/pupu.rb', line 109 def params @params end |
Class Method Details
.[](plugin, params = Hash.new) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/pupu/pupu.rb', line 99 def [](plugin, params = Hash.new) plugin = plugin.to_s if self.all.include?(plugin) self.new(plugin, params) else raise PluginNotFoundError.new(plugin) end end |
.all ⇒ Object
TODO: return Pupu object, not string
66 67 68 69 70 |
# File 'lib/pupu/pupu.rb', line 66 def all files = Dir["#{self.root_path}/*"] dirs = files.select(&File.method(:directory?)) dirs.map(&File.method(:basename)) end |
.root ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/pupu/pupu.rb', line 77 def root # TODO: it should be configurable # root = ::Pupu.root.sub(%r[#{Regexp::quote(::Pupu.root)}], '').chomp("/") # root = "./" if root.empty? # case path # when :absolute then File.join(root, ::Pupu.media_root, "pupu") # when :relative then File.join(::Pupu.media_root, "pupu") # else # # exception # end raise "Pupu.media_root has to be initialized" if ::Pupu.media_root.nil? raise Errno::ENOENT, "#{self.root_path} doesn't exist, you have to create it first!" unless File.directory?(self.root_path) @root ||= MediaPath.new(self.root_path) end |
.root=(directory) ⇒ Object
TODO: reflect changes on root method
93 94 95 96 97 |
# File 'lib/pupu/pupu.rb', line 93 def root=(directory) @root = MediaPath.new(directory) raise PupuRootNotFound unless File.exist?(@root.to_s) return @root end |
.root_path ⇒ Object
same as root, but doesn’t raise any exception
73 74 75 |
# File 'lib/pupu/pupu.rb', line 73 def root_path File.join(::Pupu.media_root, "pupu") end |
Instance Method Details
#copy_initializers ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/pupu/pupu.rb', line 176 def copy_initializers js_initializer = initializer(:javascript) css_initializer = initializer(:stylesheet) if js_initializer && (not File.exist?("#{::Pupu.media_root}/javascripts/initializers/#{File.basename(js_initializer.to_s)}")) FileUtils.mkdir_p("#{::Pupu.media_root}/javascripts/initializers") FileUtils.mv js_initializer.to_s, "#{::Pupu.media_root}/javascripts/initializers/#{File.basename(js_initializer.to_s)}" end if css_initializer && (not File.exist?("#{::Pupu.media_root}/stylesheets/initializers/#{File.basename(css_initializer.to_s)}")) FileUtils.mkdir_p("#{::Pupu.media_root}/stylesheets/initializers") FileUtils.mv css_initializer.to_s, "#{::Pupu.media_root}/stylesheets/initializers/#{File.basename(css_initializer.to_s)}" end end |
#file(path, root = self.root) ⇒ Object
195 196 197 198 199 200 |
# File 'lib/pupu/pupu.rb', line 195 def file(path, root = self.root) root = MediaPath.new(root) if root.is_a?(String) root.join(path) rescue Errno::ENOENT raise AssetNotFound, "#{soft_file(path, root)}" end |
#image(basename) ⇒ Object
139 140 141 |
# File 'lib/pupu/pupu.rb', line 139 def image(basename) file("images/#{basename}") end |
#initializer(type = :all) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/pupu/pupu.rb', line 151 def initializer(type = :all) case type when :all [self.initializer(:javascript), self.initializer(:stylesheet)] when :javascript begin file("#{@path}.js", "#{root}/initializers") rescue AssetNotFound file("#{@path}.js", "#{::Pupu.media_root}/javascripts/initializers") rescue nil end when :stylesheet begin file("#{@path}.css", "#{root}/initializers") rescue AssetNotFound file("#{@path}.css", "#{::Pupu.media_root}/stylesheets/initializers") rescue nil end else raise Exception, "#{type.to_s} is not know type of initializer" end end |
#javascript(basename) ⇒ Object
131 132 133 |
# File 'lib/pupu/pupu.rb', line 131 def javascript(basename) file("javascripts/#{basename}.js") end |
#metadata ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/pupu/pupu.rb', line 121 def return @metadata if @metadata path = self.file("metadata.yml").path hash = YAML::load_file(path) @metadata = OpenStruct.new(hash) @metadata.repository ||= @metadata.repozitory # temporary hack for old style metadata.yml rescue Errno::ENOENT # we might remove pupu directory, so metadata are missing, but we can get them from cache @metadata end |
#root ⇒ Object
116 117 118 119 |
# File 'lib/pupu/pupu.rb', line 116 def root # self.class.root.join(@path) File.join(self.class.root_path, @path) end |
#soft_file(path, root = self.root) ⇒ Object
191 192 193 |
# File 'lib/pupu/pupu.rb', line 191 def soft_file(path, root = self.root) File.join(root.to_s, path.to_s) # for files which doesn't exist so far end |
#stylesheet(basename) ⇒ Object
135 136 137 |
# File 'lib/pupu/pupu.rb', line 135 def stylesheet(basename) file("stylesheets/#{basename}.css") end |
#uninstall ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/pupu/pupu.rb', line 143 def uninstall FileUtils.rm_r self.root.to_s # TODO # self.metadata.dependants.each do |dependant| # dependant.uninstall # end end |