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
- #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.
108 109 110 |
# File 'lib/pupu/pupu.rb', line 108 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
108 109 110 |
# File 'lib/pupu/pupu.rb', line 108 def params @params end |
Class Method Details
.[](plugin, params = Hash.new) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/pupu/pupu.rb', line 98 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
65 66 67 68 69 |
# File 'lib/pupu/pupu.rb', line 65 def all files = Dir["#{self.root_path}/*"] dirs = files.select(&File.method(:directory?)) dirs.map(&File.method(:basename)) end |
.root ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pupu/pupu.rb', line 76 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
92 93 94 95 96 |
# File 'lib/pupu/pupu.rb', line 92 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
72 73 74 |
# File 'lib/pupu/pupu.rb', line 72 def root_path File.join(::Pupu.media_root, "pupu") end |
Instance Method Details
#file(path, root = self.root) ⇒ Object
165 166 167 168 |
# File 'lib/pupu/pupu.rb', line 165 def file(path, root = self.root) root = MediaPath.new(root) if root.is_a?(String) root.join(path) end |
#image(basename) ⇒ Object
138 139 140 |
# File 'lib/pupu/pupu.rb', line 138 def image(basename) file("javascripts/#{image}") end |
#initializer(type = :all) ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/pupu/pupu.rb', line 150 def initializer(type = :all) case type when :all [self.initializer(:javascript), self.initializer(:stylesheet)] when :javascript file("#{@path}.js", "#{::Pupu.media_root}/javascripts/initializers") rescue nil # TODO: fix media when :stylesheet file("#{@path}.css", "#{::Pupu.media_root}/stylesheets/initializers") rescue nil # TODO: fix media end end |
#javascript(basename) ⇒ Object
130 131 132 |
# File 'lib/pupu/pupu.rb', line 130 def javascript(basename) file("javascripts/#{basename}.js") end |
#metadata ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/pupu/pupu.rb', line 120 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
115 116 117 118 |
# File 'lib/pupu/pupu.rb', line 115 def root # self.class.root.join(@path) File.join(self.class.root_path, @path) end |
#soft_file(path, root = self.root) ⇒ Object
161 162 163 |
# File 'lib/pupu/pupu.rb', line 161 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
134 135 136 |
# File 'lib/pupu/pupu.rb', line 134 def stylesheet(basename) file("stylesheets/#{basename}.css") end |
#uninstall ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/pupu/pupu.rb', line 142 def uninstall FileUtils.rm_r self.root.to_s # TODO # self.metadata.dependants.each do |dependant| # dependant.uninstall # end end |