Class: Refinery::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/refinery/cli.rb

Constant Summary collapse

OVERRIDES =
{
  :view => {
    :glob => '*.{erb,builder}',
    :dir => 'views',
    :desc => 'view template',
  },
  :controller => {
    :glob => '*.rb',
    :dir => 'controllers',
    :desc => 'controller',
  },
  :model => {
    :glob => '*.rb',
    :dir => 'models',
    :desc => 'model',
  },
  :helper => {
    :glob => '*.rb',
    :dir => 'helpers',
    :desc => 'helper',
  },
  :presenter => {
    :glob => '*.rb',
    :dir => 'presenters',
    :desc => 'presenter',
  },
  :javascript => {
    :glob => '*.js{,.*}',
    :dir => 'assets/javascripts',
    :desc => 'javascript',
  },
  :stylesheet => {
    :glob => '*.css{,.scss}',
    :dir => 'assets/stylesheets',
    :desc => 'stylesheet',
  },
}

Instance Method Summary collapse

Instance Method Details

#override(env) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/refinery/cli.rb', line 54

def override(env)
  OVERRIDES.keys.each do |kind|
    if (which = env[kind.to_s]).present?
      return _override(kind, which)
    end
  end

  puts "You didn't specify anything valid to override. Here are some examples:"
  {
    :view => ['pages/home', 'refinery/pages/home', '**/*menu', '_menu_branch'],
    :javascript => %w(admin refinery/site_bar wymeditor**/{**/}*),
    :stylesheet => %w(home refinery/site_bar),
    :controller => %w(pages),
    :model => %w(page refinery/page),
    :helper => %w(site_bar refinery/site_bar_helper),
    :presenter => %w(refinery/page_presenter)
  }.each do |type, examples|
    examples.each do |example|
      puts "rake refinery:override #{type}=#{example}"
    end
  end
end

#uncrudify(controller, action) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/refinery/cli.rb', line 78

def uncrudify(controller, action)
  unless (controller_name = controller).present? && (action = action).present?
    abort "      You didn't specify anything to uncrudify. Here's some examples:\n      rake refinery:uncrudify controller=refinery/admin/pages action=create\n      rake refinery:uncrudify controller=products action=new\n    HELPDOC\n  end\n\n  controller_class_name = \"\#{controller_name}_controller\".classify\n  begin\n    controller_class = controller_class_name.constantize\n  rescue NameError\n    abort \"\#{controller_class_name} is not defined\"\n  end\n\n  crud_lines = Refinery.roots(:'refinery/core').join('lib', 'refinery', 'crud.rb').read\n  if (matches = crud_lines.scan(/(\\ +)(def \#{action}.+?protected)/m).first).present? &&\n     (method_lines = \"\#{matches.last.split(%r{^\#{matches.first}end}).first.strip}\\nend\".split(\"\\n\")).many?\n    indent = method_lines.second.index %r{[^ ]}\n    crud_method = method_lines.join(\"\\n\").gsub /^\#{\" \" * indent}/, \"  \"\n\n    crud_options = controller_class.try(:crudify_options) || {}\n    crud_method.gsub! '\#{options[:redirect_to_url]}', crud_options[:redirect_to_url].to_s\n    crud_method.gsub! '\#{options[:conditions].inspect}', crud_options[:conditions].inspect\n    crud_method.gsub! '\#{options[:title_attribute]}', crud_options[:title_attribute]\n    crud_method.gsub! '\#{singular_name}', crud_options[:singular_name]\n    crud_method.gsub! '\#{class_name}', crud_options[:class_name]\n    crud_method.gsub! '\#{plural_name}', crud_options[:plural_name]\n    crud_method.gsub! '\\\\\#{', '\#{'\n\n    puts crud_method\n  end\nend\n".strip_heredoc