Class: InstallTheme::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/install_theme/cli.rb

Class Method Summary collapse

Class Method Details

.execute(stdout, arguments = []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/install_theme/cli.rb', line 5

def self.execute(stdout, arguments=[])
  options = {}
  parser = OptionParser.new do |opts|
    opts.banner = "      Use any HTML template as a theme generator for your Rails app.\n      \n      Usage: \#{File.basename($0)} path/to/rails_app path/to/template content_path [options]\n      \n        Examples of paths (CSS or XPath):\n          * #header h2      - replaces the entire h2 element\n          * #header h2:text - replaces the inner HTML of the h2 element\n          * //div[@class='header']/h2        - replaces the entire h2 element\n          * //div[@class='header']/h2/text() - replaces the inner HTML of the h2 element\n      \n      Options are:\n    BANNER\n    opts.separator \"\"\n    opts.on(\"-p\", \"--partial KEY_AND_PATH\", String,\n            \"Replace the inner HTML of an element with <%= yield :key %>\",\n            \"See path examples above.\") do |arg|\n              options[:partials] ||= {}\n              key, path = arg.split(/\\s*:\\s*/)[0..1]\n              if key && path\n                options[:partials][key.strip] = path.strip\n              else\n                stdout.puts partial_format_error(arg)\n                exit\n              end\n            end\n    opts.on(\"-l\", \"--layout application\", String,\n            \"Set the layout file name.\",\n            \"Layout files are stored in app/views/layouts and will be suffixed by .html.erb or .html.haml\",\n            \"Default: application\") { |arg| options[:layout] = arg }\n    opts.on(\"-a\", \"--action posts/show\", String,\n            \"Store content extracted from content_path into Rails action.\",\n            \"Example, '-a posts/show' will create app/views/posts/show.html.erb file.\",\n            \"Default: none\") { |arg| options[:action] = arg }\n    opts.on(\"--erb\",\n            \"Generate ERb templates. Default: Yes, unless it's not.\") { |arg| options[:template_type] = 'erb' }\n    opts.on(\"--haml\",\n            \"Generate HAML templates. Default: Auto-detect\") { |arg| options[:template_type] = 'haml' }\n    opts.on(\"--no-sass\",\n            \"Don't generate sass files, just normal css. Default: false\") { |arg| options[:no_sass] = true }\n    opts.on(\"--index_path index.html\", String,\n            \"HTML page to use for application layout.\",\n            \"Default: index.html\") { |arg| options[:index_path] = arg }\n    opts.on(\"--defaults_file install_theme.yml\", String,\n            \"Select an alternate YAML file containing defaults for the theme.\",\n            \"Default: install_theme.yml\") { |arg| options[:defaults_file] = arg }\n    opts.on(\"-h\", \"--help\",\n            \"Show this help message.\") { |arg| stdout.puts opts; exit }\n    opts.on(\"-v\", \"--version\",\n            \"Show the version (which is \#{InstallTheme::VERSION}).\"\n            ) { |arg| stdout.puts InstallTheme::VERSION; exit }\n    opts.parse!(arguments)\n  end\n  options[:rails_root]    = arguments.shift\n  options[:template_root] = arguments.shift\n  options[:content_path]  = arguments.shift\n  theme = InstallTheme.new(options)\n  unless theme.valid?\n    stdout.puts parser; exit\n  end\n  theme.apply_to_target\nend\n".gsub(/^          /,'')

.partial_format_error(partial_argument) ⇒ Object



71
72
73
74
75
76
# File 'lib/install_theme/cli.rb', line 71

def self.partial_format_error(partial_argument)
  "  ERROR: Incorrect format for --partial argument \"\#{partial_argument}\".\n  Correct format is: --partial label:path\n  EOS\nend\n".gsub(/^      /, '')