Class: InstallTheme

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

Defined Under Namespace

Classes: CLI, InstallThemeGenerator

Constant Summary collapse

VERSION =
"0.7.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ InstallTheme

Returns a new instance of InstallTheme.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/install_theme.rb', line 23

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"
  @stylesheet_dir = options[:stylesheet_dir] || detect_stylesheet_dir
  @javascript_dir = options[:javascript_dir] || detect_javascript_dir
  @image_dir      = options[:image_dir] || detect_image_dir
  @layout_name    = options[:layout] || "application"
  @layout_name.gsub!(/\..*/, '') # allow application.html.erb to be passed in, but clean it up to 'application'

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

  load_template_defaults unless options[:ignore_defaults]
  @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

#content_pathObject (readonly)

Returns the value of attribute content_path.



19
20
21
# File 'lib/install_theme.rb', line 19

def content_path
  @content_path
end

#defaults_fileObject (readonly)

Returns the value of attribute defaults_file.



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

def defaults_file
  @defaults_file
end

#image_dirObject (readonly)

Returns the value of attribute image_dir.



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

def image_dir
  @image_dir
end

#index_pathObject (readonly)

Returns the value of attribute index_path.



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

def index_path
  @index_path
end

#javascript_dirObject (readonly)

Returns the value of attribute javascript_dir.



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

def javascript_dir
  @javascript_dir
end

#layout_nameObject (readonly)

Returns the value of attribute layout_name.



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

def layout_name
  @layout_name
end

#original_body_contentObject (readonly)

Returns the value of attribute original_body_content.



21
22
23
# File 'lib/install_theme.rb', line 21

def original_body_content
  @original_body_content
end

#original_named_yieldsObject (readonly)

Returns the value of attribute original_named_yields.



21
22
23
# File 'lib/install_theme.rb', line 21

def original_named_yields
  @original_named_yields
end

#partialsObject (readonly)

Returns the value of attribute partials.



19
20
21
# File 'lib/install_theme.rb', line 19

def partials
  @partials
end

#rails_rootObject (readonly)

Returns the value of attribute rails_root.



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

def rails_root
  @rails_root
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



20
21
22
# File 'lib/install_theme.rb', line 20

def stdout
  @stdout
end

#stylesheet_dirObject (readonly)

Returns the value of attribute stylesheet_dir.



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

def stylesheet_dir
  @stylesheet_dir
end

#template_rootObject (readonly)

Returns the value of attribute template_root.



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

def template_root
  @template_root
end

#template_typeObject (readonly)

Returns the value of attribute template_type.



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

def template_type
  @template_type
end

Instance Method Details

#apply_to_target(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/install_theme.rb', line 46

def apply_to_target(options = {})
  @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/application.html.erb') if haml?
  prepare_sample_controller_and_view
  prepare_layout_partials
  prepare_assets
  prepare_helpers
  run_generator(options)
  show_readme
end

#erb?Boolean

Returns:

  • (Boolean)


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

def erb?
  template_type == 'erb'
end

#haml?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/install_theme.rb', line 75

def haml?
  template_type == 'haml'
end

#setup_template_temp_pathObject



67
68
69
70
71
72
73
# File 'lib/install_theme.rb', line 67

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.



61
62
63
64
65
# File 'lib/install_theme.rb', line 61

def template_temp_path
  @template_temp_path ||= begin
    template_path = File.join(tmp_dir, "install_theme", "templates")
  end
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  template_root && File.exist?(template_root) &&
  rails_root && File.exist?(rails_root) &&
  content_path
end