Class: Tay::CLI::Generate

Inherits:
Thor
  • Object
show all
Includes:
Helpers, Thor::Actions
Defined in:
lib/tay/cli/generate.rb,
lib/tay/cli/generators/page_action.rb,
lib/tay/cli/generators/options_page.rb,
lib/tay/cli/generators/browser_action.rb,
lib/tay/cli/generators/content_script.rb

Constant Summary

Constants included from Helpers

Helpers::DEFAULT_TAYFILE

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



12
13
14
# File 'lib/tay/cli/generate.rb', line 12

def self.source_root
  File.expand_path('generators/templates', File.dirname(__FILE__))
end

Instance Method Details

#browser_actionObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tay/cli/generators/browser_action.rb', line 7

def browser_action
  raise Tay::InvalidSpecification.new("Browser action already specified") if spec.browser_action
  raise Tay::InvalidSpecification.new("You cannot have both browser and page actions") if spec.browser_action
  raise Tay::InvalidSpecification.new("You cannot have both browser actions and packaged apps") if spec.packaged_app

  fs_name = Utils.filesystem_name(options['action-name'])
  copy_file('browser_action/action.js', javascript_dir.join(fs_name+ '.js'))
  copy_file('browser_action/action.css', stylesheet_dir.join(fs_name+ '.css'))

  create_file(html_dir.join(fs_name + '.html'), render_template('browser_action/action.html', :fs_name => fs_name))

  inject_tayfile_content(render_template('browser_action/tayfile', :fs_name => fs_name))
end

#content_scriptObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tay/cli/generators/content_script.rb', line 11

def content_script
  fs_name = Utils.filesystem_name(options['script-name'])

  unless options['no-javascript']
    copy_file('content_script/content_script.js', javascript_dir.join(fs_name + '.js'))
  end
  unless options['no-stylesheet']
    copy_file('content_script/content_script.css', stylesheet_dir.join(fs_name + '.css'))
  end
  inject_tayfile_content(render_template('content_script/tayfile', :fs_name => fs_name))
end

#options_pageObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/tay/cli/generators/options_page.rb', line 5

def options_page
  copy_file('options_page/options.js', javascript_dir.join('options.js'))
  copy_file('options_page/options_page.js', javascript_dir.join('options_page.js'))
  copy_file('options_page/options_server.js', javascript_dir.join('options_server.js'))
  copy_file('options_page/options_page.css', stylesheet_dir.join('options_page.css'))

  create_file(html_dir.join('options_page.html'), render_template('options_page/options_page.html'))

  inject_tayfile_content(render_template('options_page/tayfile'))
end

#page_actionObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/tay/cli/generators/page_action.rb', line 7

def page_action
  raise Tay::InvalidSpecification.new("Page action already specified") if spec.page_action
  raise Tay::InvalidSpecification.new("You cannot have both page and browser actions") if spec.browser_action
  raise Tay::InvalidSpecification.new("You cannot have both page actions and packaged apps") if spec.packaged_app

  fs_name = Utils.filesystem_name(options['action-name'])
  copy_file('page_action/icon.png', asset_dir.join(fs_name + '_icon.png'))
  copy_file('page_action/controller.js', javascript_dir.join(fs_name + '_controller.js'))
  inject_tayfile_content(render_template('page_action/tayfile', :fs_name => fs_name))
end