Class: VOODOO::Extension
- Inherits:
-
Object
- Object
- VOODOO::Extension
- Defined in:
- lib/voodoo/extension.rb
Instance Attribute Summary collapse
-
#folder ⇒ Object
readonly
Returns the value of attribute folder.
-
#manifest ⇒ Object
Returns the value of attribute manifest.
Instance Method Summary collapse
- #add_background_script(content: nil, file: nil) ⇒ Object
- #add_content_script(matches, js: [], css: []) ⇒ Object
-
#initialize ⇒ Extension
constructor
A new instance of Extension.
- #save ⇒ Object
- #unlink ⇒ Object
Constructor Details
#initialize ⇒ Extension
Returns a new instance of Extension.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/voodoo/extension.rb', line 12 def initialize @id = 0 @folder = Dir.mktmpdir @manifest = { name: '~', author: '~', description: '', version: '0.0.1', manifest_version: 2, background: { scripts: [] }, permissions: [], content_scripts: [] } end |
Instance Attribute Details
#folder ⇒ Object (readonly)
Returns the value of attribute folder.
10 11 12 |
# File 'lib/voodoo/extension.rb', line 10 def folder @folder end |
#manifest ⇒ Object
Returns the value of attribute manifest.
9 10 11 |
# File 'lib/voodoo/extension.rb', line 9 def manifest @manifest end |
Instance Method Details
#add_background_script(content: nil, file: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/voodoo/extension.rb', line 29 def add_background_script(content: nil, file: nil) if content == nil && file != nil content = File.read file end if content == nil raise StandardError.new(':content or :file argument are required') end path = add_file(content, with_extension: '.js') @manifest[:background][:scripts] << path end |
#add_content_script(matches, js: [], css: []) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/voodoo/extension.rb', line 40 def add_content_script(matches, js: [], css: []) matches = [matches] unless matches.is_a? Array js = js.map { |str| add_file(str) } css = css.map { |str| add_file(str, with_extension: '.css') } @manifest[:content_scripts] << { js: js, css: css, matches: matches } end |
#save ⇒ Object
53 54 55 56 57 58 |
# File 'lib/voodoo/extension.rb', line 53 def save @manifest[:permissions] = @manifest[:permissions].uniq manifest_path = File.join(@folder, 'manifest.json') File.write(manifest_path, JSON.generate(@manifest)) return @folder end |
#unlink ⇒ Object
60 61 62 |
# File 'lib/voodoo/extension.rb', line 60 def unlink FileUtils.rm_r(@folder, :force=>true) end |