Class: InstallTheme
- Inherits:
-
Object
- Object
- InstallTheme
- Defined in:
- lib/install_theme.rb,
lib/install_theme/cli.rb
Defined Under Namespace
Modules: Parsers Classes: CLI, InstallThemeGenerator
Constant Summary collapse
- VERSION =
"0.8.2"
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.
-
#no_sass ⇒ Object
readonly
Returns the value of attribute no_sass.
-
#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.
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 |
# File 'lib/install_theme.rb', line 21 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" @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] @stylesheet_dir = [:stylesheet_dir] || @stylesheet_dir || detect_stylesheet_dir @javascript_dir = [:javascript_dir] || @javascript_dir || detect_javascript_dir @image_dir = [:image_dir] || @image_dir || detect_image_dir @no_sass = [:no_sass] || @no_sass || false @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.
13 14 15 |
# File 'lib/install_theme.rb', line 13 def action @action end |
#content_path ⇒ Object (readonly)
Returns the value of attribute content_path.
16 17 18 |
# File 'lib/install_theme.rb', line 16 def content_path @content_path end |
#defaults_file ⇒ Object (readonly)
Returns the value of attribute defaults_file.
15 16 17 |
# File 'lib/install_theme.rb', line 15 def defaults_file @defaults_file end |
#image_dir ⇒ Object (readonly)
Returns the value of attribute image_dir.
14 15 16 |
# File 'lib/install_theme.rb', line 14 def image_dir @image_dir end |
#index_path ⇒ Object (readonly)
Returns the value of attribute index_path.
12 13 14 |
# File 'lib/install_theme.rb', line 12 def index_path @index_path end |
#javascript_dir ⇒ Object (readonly)
Returns the value of attribute javascript_dir.
14 15 16 |
# File 'lib/install_theme.rb', line 14 def javascript_dir @javascript_dir end |
#layout_name ⇒ Object (readonly)
Returns the value of attribute layout_name.
13 14 15 |
# File 'lib/install_theme.rb', line 13 def layout_name @layout_name end |
#no_sass ⇒ Object (readonly)
Returns the value of attribute no_sass.
19 20 21 |
# File 'lib/install_theme.rb', line 19 def no_sass @no_sass end |
#original_body_content ⇒ Object (readonly)
Returns the value of attribute original_body_content.
18 19 20 |
# File 'lib/install_theme.rb', line 18 def original_body_content @original_body_content end |
#original_named_yields ⇒ Object (readonly)
Returns the value of attribute original_named_yields.
18 19 20 |
# File 'lib/install_theme.rb', line 18 def original_named_yields @original_named_yields end |
#partials ⇒ Object (readonly)
Returns the value of attribute partials.
16 17 18 |
# File 'lib/install_theme.rb', line 16 def partials @partials end |
#rails_root ⇒ Object (readonly)
Returns the value of attribute rails_root.
12 13 14 |
# File 'lib/install_theme.rb', line 12 def rails_root @rails_root end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
17 18 19 |
# File 'lib/install_theme.rb', line 17 def stdout @stdout end |
#stylesheet_dir ⇒ Object (readonly)
Returns the value of attribute stylesheet_dir.
14 15 16 |
# File 'lib/install_theme.rb', line 14 def stylesheet_dir @stylesheet_dir end |
#template_root ⇒ Object (readonly)
Returns the value of attribute template_root.
12 13 14 |
# File 'lib/install_theme.rb', line 12 def template_root @template_root end |
#template_type ⇒ Object (readonly)
Returns the value of attribute template_type.
12 13 14 |
# File 'lib/install_theme.rb', line 12 def template_type @template_type end |
Instance Method Details
#apply_to_target(options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/install_theme.rb', line 48 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
83 84 85 |
# File 'lib/install_theme.rb', line 83 def erb? template_type == 'erb' end |
#haml? ⇒ Boolean
79 80 81 |
# File 'lib/install_theme.rb', line 79 def haml? template_type == 'haml' end |
#setup_template_temp_path ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/install_theme.rb', line 71 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.
65 66 67 68 69 |
# File 'lib/install_theme.rb', line 65 def template_temp_path @template_temp_path ||= begin template_path = File.join(tmp_dir, "install_theme", "templates") end end |
#valid? ⇒ Boolean
87 88 89 90 91 |
# File 'lib/install_theme.rb', line 87 def valid? template_root && File.exist?(template_root) && rails_root && File.exist?(rails_root) && content_path end |