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 end end |
.all ⇒ Object
TODO: return Pupu object, not string
65 66 67 68 69 |
# File 'lib/pupu/pupu.rb', line 65 def all Dir["#{self.root}/*"].select do |item| File.directory?(item) end.map { |entry| File.basename(entry).to_s } 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, "#{::Pupu.media_root}/pupu doesn't exist, you have to create it first!" unless File.directory?File.join(::Pupu.media_root, "pupu") @root ||= MediaPath.new(File.join(::Pupu.media_root, "pupu")) 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
163 164 165 166 |
# File 'lib/pupu/pupu.rb', line 163 def file(path, root = self.root) root = MediaPath.new(root) if root.is_a?(String) root.join(path) end |
#image(basename) ⇒ Object
136 137 138 |
# File 'lib/pupu/pupu.rb', line 136 def image(basename) file("javascripts/#{image}") end |
#initializer(type = :all) ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/pupu/pupu.rb', line 148 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
128 129 130 |
# File 'lib/pupu/pupu.rb', line 128 def javascript(basename) file("javascripts/#{basename}.js") end |
#metadata ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/pupu/pupu.rb', line 119 def return @metadata if @metadata path = self.file("metadata.yml").path hash = YAML::load_file(path) @metadata = OpenStruct.new(hash) 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 |
# File 'lib/pupu/pupu.rb', line 115 def root self.class.root.join(@path) end |
#soft_file(path, root = self.root) ⇒ Object
159 160 161 |
# File 'lib/pupu/pupu.rb', line 159 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
132 133 134 |
# File 'lib/pupu/pupu.rb', line 132 def stylesheet(basename) file("stylesheets/#{basename}.css") end |
#uninstall ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/pupu/pupu.rb', line 140 def uninstall FileUtils.rm_r self.root.to_s # TODO # self.metadata.dependants.each do |dependant| # dependant.uninstall # end end |