Class: Tay::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/tay/specification.rb,
lib/tay/specification/action.rb,
lib/tay/specification/web_intent.rb,
lib/tay/specification/nacl_module.rb,
lib/tay/specification/page_action.rb,
lib/tay/specification/packaged_app.rb,
lib/tay/specification/browser_action.rb,
lib/tay/specification/content_script.rb

Overview

A tay specification helps you define the functionality that the extension provides. It also serves as the data source that it used to generate the manifest.json file.

Defined Under Namespace

Classes: Action, BrowserAction, ContentScript, NaClModule, PackagedApp, PageAction, WebIntent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Specification

Returns a new instance of Specification.

Yields:

  • (_self)

Yield Parameters:



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/tay/specification.rb', line 174

def initialize(&block)
  @nacl_modules = []
  @overriden_pages = {}
  @web_accessible_resources = []
  @permissions = []
  @background_scripts = []
  @content_scripts = []
  @web_intents = []
  @icons = {}
  @stylesheets = []
  @javascripts = []
  @source_directories = %w{img assets html}

  yield self
end

Instance Attribute Details

#background_pageObject

Path to an HTML file that will be used as the background page



37
38
39
# File 'lib/tay/specification.rb', line 37

def background_page
  @background_page
end

#background_scriptsObject

An array javascript file paths that will run in the background

code.google.com/chrome/extensions/background_pages.html



96
97
98
# File 'lib/tay/specification.rb', line 96

def background_scripts
  @background_scripts
end

#browser_actionObject (readonly)

A Tay::Specification::BrowserAction or nil



130
131
132
# File 'lib/tay/specification.rb', line 130

def browser_action
  @browser_action
end

#content_scriptsObject

An array of Tay::Specification::ContentScript objects



86
87
88
# File 'lib/tay/specification.rb', line 86

def content_scripts
  @content_scripts
end

#content_security_policyObject



49
50
51
# File 'lib/tay/specification.rb', line 49

def content_security_policy
  @content_security_policy
end

#default_localeObject



33
34
35
# File 'lib/tay/specification.rb', line 33

def default_locale
  @default_locale
end

#descriptionObject



25
26
27
# File 'lib/tay/specification.rb', line 25

def description
  @description
end

#homepageObject



29
30
31
# File 'lib/tay/specification.rb', line 29

def homepage
  @homepage
end

#iconsObject



122
123
124
# File 'lib/tay/specification.rb', line 122

def icons
  @icons
end

#incognito_modeObject



57
58
59
# File 'lib/tay/specification.rb', line 57

def incognito_mode
  @incognito_mode
end

#javascriptsObject

An array of javascript paths that will be copied to the build



112
113
114
# File 'lib/tay/specification.rb', line 112

def javascripts
  @javascripts
end

#key_pathObject

Get the path to the private key for this extension



172
173
174
# File 'lib/tay/specification.rb', line 172

def key_path
  @key_path
end

#manifest_dataObject

If you set this to a hash, it will be merged on top of the generated manifest. This is useful to force override of specific values



78
79
80
# File 'lib/tay/specification.rb', line 78

def manifest_data
  @manifest_data
end

#minimum_chrome_versionObject



53
54
55
# File 'lib/tay/specification.rb', line 53

def minimum_chrome_version
  @minimum_chrome_version
end

#nacl_modulesObject

An array of Tay::Specification::NaClModule



82
83
84
# File 'lib/tay/specification.rb', line 82

def nacl_modules
  @nacl_modules
end

#nameObject



17
18
19
# File 'lib/tay/specification.rb', line 17

def name
  @name
end

#offline_enabledObject



61
62
63
# File 'lib/tay/specification.rb', line 61

def offline_enabled
  @offline_enabled
end

#omnibox_keywordObject



45
46
47
# File 'lib/tay/specification.rb', line 45

def omnibox_keyword
  @omnibox_keyword
end

#options_pageObject



41
42
43
# File 'lib/tay/specification.rb', line 41

def options_page
  @options_page
end

#overriden_pagesObject (readonly)

A map of Chrome page types to HTML files



126
127
128
# File 'lib/tay/specification.rb', line 126

def overriden_pages
  @overriden_pages
end

#packaged_appObject (readonly)

A Tay::Specification::PackagedApp or nil



138
139
140
# File 'lib/tay/specification.rb', line 138

def packaged_app
  @packaged_app
end

#page_actionObject (readonly)

A Tay::Specification::PageAction or nil



134
135
136
# File 'lib/tay/specification.rb', line 134

def page_action
  @page_action
end

#permissionsObject

An array of permissions the extension requires

code.google.com/chrome/extensions/manifest.html#permissions



108
109
110
# File 'lib/tay/specification.rb', line 108

def permissions
  @permissions
end

#requires_3d_css_transitionsObject

Set this to true to mark the extension as requiring 3d css support



69
70
71
# File 'lib/tay/specification.rb', line 69

def requires_3d_css_transitions
  @requires_3d_css_transitions
end

#requires_webglObject

Set this to true to mark the extension as requiring webgl support



65
66
67
# File 'lib/tay/specification.rb', line 65

def requires_webgl
  @requires_webgl
end

#source_directoriesObject

An array of directories that will be copied to the build directory. Defaults to “img”, “assets”, and “html”, all files are run through Tilt before being copied

If just a directory name is passed, it is assumed to be a sub-dir of src, and will be copied as the directory name, eg:

spec.source_directories << “extras”

# copies src/extras to build/extras

If you provide a path, it is relative to the root directory, and will be copied to the build directory under this full relative path, eg:

spec.source_directories << “non_code/fonts”

# copies non_code/fonts to build/non_code/fonts

If you need finer control over where files end up, you can also push an object on to this list detailing the source directory, and the directory it will be placed in under the build dir. You can optionally specify whether to run through Tilt or not (default: yes). eg:

spec.source_directories <<

:from => "vendor/bootstrap/img",
:as => "img",
:use_tilt => false

# copies vendor/bootstrap/img/* to build/img



167
168
169
# File 'lib/tay/specification.rb', line 167

def source_directories
  @source_directories
end

#stylesheetsObject

An array of stylesheet paths that will be copied to the build



116
117
118
# File 'lib/tay/specification.rb', line 116

def stylesheets
  @stylesheets
end

#update_urlObject



73
74
75
# File 'lib/tay/specification.rb', line 73

def update_url
  @update_url
end

#versionObject



21
22
23
# File 'lib/tay/specification.rb', line 21

def version
  @version
end

#web_accessible_resourcesObject

An array of paths considered “web accessible”

code.google.com/chrome/extensions/manifest.html#web_accessible_resources



102
103
104
# File 'lib/tay/specification.rb', line 102

def web_accessible_resources
  @web_accessible_resources
end

#web_intentsObject

An array of Tay::Specification::WebIntent objects



90
91
92
# File 'lib/tay/specification.rb', line 90

def web_intents
  @web_intents
end

Instance Method Details

#add_browser_action {|@browser_action| ... } ⇒ Object

Create a new Tay::Specification::BrowserAction and pass it to the block for set up.



199
200
201
202
203
# File 'lib/tay/specification.rb', line 199

def add_browser_action(&block)
  raise Tay::InvalidSpecification.new('Browser action already set up') if @browser_action
  @browser_action = BrowserAction.new
  yield @browser_action
end

#add_content_script {|content_script| ... } ⇒ Object

Add a content script to this extension. It will be passed to the block for set up. See Tay::Specification::ContentScript

Yields:

  • (content_script)


226
227
228
229
230
# File 'lib/tay/specification.rb', line 226

def add_content_script(&block)
  content_script = ContentScript.new
  yield content_script
  @content_scripts << content_script
end

#add_icon(size, path) ⇒ Object

Provide the path of the icon to be used at a certain size



192
193
194
# File 'lib/tay/specification.rb', line 192

def add_icon(size, path)
  @icons[size.to_i] = path
end

#add_nacl_module {|nacl_module| ... } ⇒ Object

Add a native client module to this extension. It will be passed to the block for set up. See Tay::Specification::NaClModule

Yields:

  • (nacl_module)


244
245
246
247
248
# File 'lib/tay/specification.rb', line 244

def add_nacl_module(&block)
  nacl_module = NaClModule.new
  yield nacl_module
  @nacl_modules << nacl_module
end

#add_packaged_app {|@packaged_app| ... } ⇒ Object

Create a new Tay::Specification::BrowserAction and pass it to the block for set up.



217
218
219
220
221
# File 'lib/tay/specification.rb', line 217

def add_packaged_app(&block)
  raise Tay::InvalidSpecification.new('Packaged app already set up') if @packaged_app
  @packaged_app = PackagedApp.new
  yield @packaged_app
end

#add_page_action {|@page_action| ... } ⇒ Object

Create a new Tay::Specification::BrowserAction and pass it to the block for set up.

Yields:

Raises:



208
209
210
211
212
# File 'lib/tay/specification.rb', line 208

def add_page_action(&block)
  raise Tay::InvalidSpecification.new('Page action already set up') if @page_action
  @page_action = PageAction.new
  yield @page_action
end

#add_web_intent {|web_intent| ... } ⇒ Object

Add a web intent to this extension. It will be passed to the block for set up. See Tay::Specification::WebIntent

Yields:

  • (web_intent)


235
236
237
238
239
# File 'lib/tay/specification.rb', line 235

def add_web_intent(&block)
  web_intent = WebIntent.new
  yield web_intent
  @web_intents << web_intent
end

#all_javascript_pathsObject

Return all the javascript paths in the spec, included those nested inside other objects



261
262
263
264
265
266
267
# File 'lib/tay/specification.rb', line 261

def all_javascript_paths
  all_paths = []
  all_paths += @javascripts
  all_paths += @background_scripts
  all_paths += @content_scripts.map { |cs| cs.javascripts }.compact
  all_paths.flatten.uniq
end

#all_stylesheet_pathsObject

Return all the stylesheet paths in the spec, included those nested inside other objects



272
273
274
275
276
277
# File 'lib/tay/specification.rb', line 272

def all_stylesheet_paths
  all_paths = []
  all_paths += @stylesheets
  all_paths += @content_scripts.map { |cs| cs.stylesheets }.compact
  all_paths.flatten.uniq
end

#has_permission?(permission) ⇒ Boolean

Does the specification have a certain permission?

Returns:

  • (Boolean)


287
288
289
# File 'lib/tay/specification.rb', line 287

def has_permission?(permission)
  permissions.include?(permission)
end

#override_page(page_type, path) ⇒ Object

Override a built in Chrome page with your own HTML file

code.google.com/chrome/extensions/override.html



254
255
256
# File 'lib/tay/specification.rb', line 254

def override_page(page_type, path)
  @overriden_pages[page_type] = path
end