Class: InstallTheme

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options = {})
  @template_root  = File.expand_path(options[:template_root] || File.dirname('.'))
  @rails_root     = File.expand_path(options[:rails_root] || File.dirname('.'))
  @template_type  = (options[:template_type] || detect_template).to_s
  @defaults_file  = options[:defaults_file]  || "install_theme.yml"
  @layout_name    = options[:layout]         || "application"
  @layout_name.gsub!(/\..*/, '') # allow application.html.erb to be passed in, but clean it up to 'application'
  @action         = options[:action]

  @stdout         = options[:stdout] || $stdout

  load_template_defaults unless options[:ignore_defaults]

  @stylesheet_dir = options[:stylesheet_dir] || @stylesheet_dir || detect_stylesheet_dir
  @javascript_dir = options[:javascript_dir] || @javascript_dir || detect_javascript_dir
  @image_dir      = options[:image_dir]      || @image_dir || detect_image_dir
  @no_sass        = options[:no_sass]        || @no_sass || false

  @index_path     = options[:index_path] || @index_path || "index.html"
  @content_path   = options[:content_path] || @content_path
  @partials       ||= {}
  @partials.merge!(options[:partials]) if options[:partials]
  
  create_install_theme_yml
  setup_template_temp_path
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



13
14
15
# File 'lib/install_theme.rb', line 13

def action
  @action
end

#content_pathObject (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_fileObject (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_dirObject (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_pathObject (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_dirObject (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_nameObject (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_sassObject (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_contentObject (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_yieldsObject (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

#partialsObject (readonly)

Returns the value of attribute partials.



16
17
18
# File 'lib/install_theme.rb', line 16

def partials
  @partials
end

#rails_rootObject (readonly)

Returns the value of attribute rails_root.



12
13
14
# File 'lib/install_theme.rb', line 12

def rails_root
  @rails_root
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



17
18
19
# File 'lib/install_theme.rb', line 17

def stdout
  @stdout
end

#stylesheet_dirObject (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_rootObject (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_typeObject (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(options = {})
  require_haml if haml?
  @stdout = options[: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(options)
  show_readme
end

#erb?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/install_theme.rb', line 83

def erb?
  template_type == 'erb'
end

#haml?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/install_theme.rb', line 79

def haml?
  template_type == 'haml'
end

#setup_template_temp_pathObject



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_pathObject

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

Returns:

  • (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