Class: Tay::ManifestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/tay/manifest_generator.rb

Overview

Takes a Tay::Specification and turns it in to a JSON representation that is eventually saved in to the manifest.json file.

It also does basic sanity checks for missing required fields and common mistakes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specification) ⇒ ManifestGenerator

Returns a new instance of ManifestGenerator.



13
14
15
# File 'lib/tay/manifest_generator.rb', line 13

def initialize(specification)
  @spec = specification
end

Instance Attribute Details

#specObject (readonly)

Pointer to the relevant Tay::Specification



11
12
13
# File 'lib/tay/manifest_generator.rb', line 11

def spec
  @spec
end

Instance Method Details

#spec_as_jsonObject

Return the JSON representation of the specification



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tay/manifest_generator.rb', line 19

def spec_as_json
  json = {
    :name => spec.name,
    :version => spec.version,
    :manifest_version => calculate_manifest_version
  }

  json[:description] = spec.description if spec.description
  json[:icons] = spec.icons
  json[:default_locale] = spec.default_locale if spec.default_locale
  json[:browser_action] = action_as_json(spec.browser_action) if spec.browser_action
  json[:page_action] = action_as_json(spec.page_action) if spec.page_action
  json[:app] = packaged_app_as_json if spec.packaged_app
  if spec.background_page
    json[:background] = { :page => spec.background_page }
  end
  unless spec.background_scripts.empty?
    json[:background] = { :scripts => spec.background_scripts }
  end
  json[:chrome_url_overrides] = spec.overriden_pages unless spec.overriden_pages.empty?
  json[:content_scripts] = content_scripts_as_json unless spec.content_scripts.empty?
  json[:content_security_policy] = spec.content_security_policy if spec.content_security_policy
  json[:homepage_url] = spec.homepage if spec.homepage
  json[:incognito] = spec.incognito_mode if spec.incognito_mode
  json[:intents] = web_intents_as_json unless spec.web_intents.empty?
  json[:minimum_chrome_version] = spec.minimum_chrome_version if spec.minimum_chrome_version
  json[:nacl_modules] = nacl_modules_as_json unless spec.nacl_modules.empty?
  json[:offline_enabled] = spec.offline_enabled unless spec.offline_enabled.nil?
  json[:omnibox] = spec.omnibox_keyword if spec.omnibox_keyword
  json[:options_page] = spec.options_page if spec.options_page
  json[:permissions] = spec.permissions unless spec.permissions.empty?
  json[:requirements] = requirements_as_json if has_requirements?
  json[:update_url] = spec.update_url if spec.update_url
  json[:web_accessible_resources] = spec.web_accessible_resources unless spec.web_accessible_resources.empty?

  json
end