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.8.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

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(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'
  @action         = options[:action]

  @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

#actionObject (readonly)

Returns the value of attribute action.



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

def action
  @action
end

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

#partialsObject (readonly)

Returns the value of attribute partials.



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

def partials
  @partials
end

#rails_rootObject (readonly)

Returns the value of attribute rails_root.



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

def rails_root
  @rails_root
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

#stylesheet_dirObject (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_rootObject (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_typeObject (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(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)


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

def erb?
  template_type == 'erb'
end

#haml?Boolean

Returns:

  • (Boolean)


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

def haml?
  template_type == 'haml'
end

#setup_template_temp_pathObject



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_pathObject

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

Returns:

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