Class: InstallTheme
- Inherits:
-
Object
- Object
- InstallTheme
- Defined in:
- lib/install_theme.rb,
lib/install_theme/cli.rb
Defined Under Namespace
Classes: CLI, InstallThemeGenerator
Constant Summary collapse
- VERSION =
"0.8.0"
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#content_path ⇒ Object
readonly
Returns the value of attribute content_path.
-
#defaults_file ⇒ Object
readonly
Returns the value of attribute defaults_file.
-
#image_dir ⇒ Object
readonly
Returns the value of attribute image_dir.
-
#index_path ⇒ Object
readonly
Returns the value of attribute index_path.
-
#javascript_dir ⇒ Object
readonly
Returns the value of attribute javascript_dir.
-
#layout_name ⇒ Object
readonly
Returns the value of attribute layout_name.
-
#original_body_content ⇒ Object
readonly
Returns the value of attribute original_body_content.
-
#original_named_yields ⇒ Object
readonly
Returns the value of attribute original_named_yields.
-
#partials ⇒ Object
readonly
Returns the value of attribute partials.
-
#rails_root ⇒ Object
readonly
Returns the value of attribute rails_root.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
-
#stylesheet_dir ⇒ Object
readonly
Returns the value of attribute stylesheet_dir.
-
#template_root ⇒ Object
readonly
Returns the value of attribute template_root.
-
#template_type ⇒ Object
readonly
Returns the value of attribute template_type.
Instance Method Summary collapse
- #apply_to_target(options = {}) ⇒ Object
- #erb? ⇒ Boolean
- #haml? ⇒ Boolean
-
#initialize(options = {}) ⇒ InstallTheme
constructor
A new instance of InstallTheme.
- #setup_template_temp_path ⇒ Object
-
#template_temp_path ⇒ Object
This generator’s templates folder is temporary and is accessed via source_root within the generator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ InstallTheme
Returns a new instance of InstallTheme.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/install_theme.rb', line 19 def initialize( = {}) @template_root = File.([:template_root] || File.dirname('.')) @rails_root = File.([:rails_root] || File.dirname('.')) @template_type = ([:template_type] || detect_template).to_s @defaults_file = [:defaults_file] || "install_theme.yml" @stylesheet_dir = [:stylesheet_dir] || detect_stylesheet_dir @javascript_dir = [:javascript_dir] || detect_javascript_dir @image_dir = [:image_dir] || detect_image_dir @layout_name = [:layout] || "application" @layout_name.gsub!(/\..*/, '') # allow application.html.erb to be passed in, but clean it up to 'application' @action = [:action] @stdout = [:stdout] || $stdout load_template_defaults unless [:ignore_defaults] @index_path = [:index_path] || @index_path || "index.html" @content_path = [:content_path] || @content_path @partials ||= {} @partials.merge!([:partials]) if [:partials] create_install_theme_yml setup_template_temp_path end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
12 13 14 |
# File 'lib/install_theme.rb', line 12 def action @action end |
#content_path ⇒ Object (readonly)
Returns the value of attribute content_path.
15 16 17 |
# File 'lib/install_theme.rb', line 15 def content_path @content_path end |
#defaults_file ⇒ Object (readonly)
Returns the value of attribute defaults_file.
14 15 16 |
# File 'lib/install_theme.rb', line 14 def defaults_file @defaults_file end |
#image_dir ⇒ Object (readonly)
Returns the value of attribute image_dir.
13 14 15 |
# File 'lib/install_theme.rb', line 13 def image_dir @image_dir end |
#index_path ⇒ Object (readonly)
Returns the value of attribute index_path.
11 12 13 |
# File 'lib/install_theme.rb', line 11 def index_path @index_path end |
#javascript_dir ⇒ Object (readonly)
Returns the value of attribute javascript_dir.
13 14 15 |
# File 'lib/install_theme.rb', line 13 def javascript_dir @javascript_dir end |
#layout_name ⇒ Object (readonly)
Returns the value of attribute layout_name.
12 13 14 |
# File 'lib/install_theme.rb', line 12 def layout_name @layout_name end |
#original_body_content ⇒ Object (readonly)
Returns the value of attribute original_body_content.
17 18 19 |
# File 'lib/install_theme.rb', line 17 def original_body_content @original_body_content end |
#original_named_yields ⇒ Object (readonly)
Returns the value of attribute original_named_yields.
17 18 19 |
# File 'lib/install_theme.rb', line 17 def original_named_yields @original_named_yields end |
#partials ⇒ Object (readonly)
Returns the value of attribute partials.
15 16 17 |
# File 'lib/install_theme.rb', line 15 def partials @partials end |
#rails_root ⇒ Object (readonly)
Returns the value of attribute rails_root.
11 12 13 |
# File 'lib/install_theme.rb', line 11 def rails_root @rails_root end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
16 17 18 |
# File 'lib/install_theme.rb', line 16 def stdout @stdout end |
#stylesheet_dir ⇒ Object (readonly)
Returns the value of attribute stylesheet_dir.
13 14 15 |
# File 'lib/install_theme.rb', line 13 def stylesheet_dir @stylesheet_dir end |
#template_root ⇒ Object (readonly)
Returns the value of attribute template_root.
11 12 13 |
# File 'lib/install_theme.rb', line 11 def template_root @template_root end |
#template_type ⇒ Object (readonly)
Returns the value of attribute template_type.
11 12 13 |
# File 'lib/install_theme.rb', line 11 def template_type @template_type end |
Instance Method Details
#apply_to_target(options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/install_theme.rb', line 43 def apply_to_target( = {}) require_haml if haml? @stdout = [:stdout] || @stdout || $stdout @original_named_yields = {} convert_file_to_layout(index_path, "app/views/layouts/#{layout_name}.html.erb") convert_to_haml("app/views/layouts/#{layout_name}.html.erb") if haml? prepare_action prepare_sample_controller_and_view prepare_layout_partials prepare_assets prepare_helpers run_generator() show_readme end |
#erb? ⇒ Boolean
78 79 80 |
# File 'lib/install_theme.rb', line 78 def erb? template_type == 'erb' end |
#haml? ⇒ Boolean
74 75 76 |
# File 'lib/install_theme.rb', line 74 def haml? template_type == 'haml' end |
#setup_template_temp_path ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/install_theme.rb', line 66 def setup_template_temp_path FileUtils.rm_rf(template_temp_path) FileUtils.mkdir_p(template_temp_path) %w[app/views/layouts public/images public/javascripts public/stylesheets].each do |app_path| FileUtils.mkdir_p(File.join(template_temp_path, app_path)) end end |
#template_temp_path ⇒ Object
This generator’s templates folder is temporary and is accessed via source_root within the generator.
60 61 62 63 64 |
# File 'lib/install_theme.rb', line 60 def template_temp_path @template_temp_path ||= begin template_path = File.join(tmp_dir, "install_theme", "templates") end end |
#valid? ⇒ Boolean
82 83 84 85 86 |
# File 'lib/install_theme.rb', line 82 def valid? template_root && File.exist?(template_root) && rails_root && File.exist?(rails_root) && content_path end |