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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ InstallTheme

Returns a new instance of InstallTheme.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/install_theme.rb', line 17

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
  @index_path     = options[:index_path] || "index.html"
  @content_id     = options[:content_id] || "content"
  @inside_yields  = options[:inside_yields] || {}
  @stylesheet_dir = options[:stylesheet_dir] || detect_stylesheet_dir
  @javascript_dir = options[:javascript_dir] || detect_javascript_dir
  @image_dir      = options[:image_dir] || detect_image_dir
  @stdout         = options[:stdout] || $stdout
  
  setup_template_temp_path
end

Instance Attribute Details

#content_idObject (readonly)

Returns the value of attribute content_id.



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

def content_id
  @content_id
end

#image_dirObject (readonly)

Returns the value of attribute image_dir.



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

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

#inside_yieldsObject (readonly)

Returns the value of attribute inside_yields.



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

def inside_yields
  @inside_yields
end

#inside_yields_originalsObject (readonly)

Returns the value of attribute inside_yields_originals.



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

def inside_yields_originals
  @inside_yields_originals
end

#javascript_dirObject (readonly)

Returns the value of attribute javascript_dir.



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

def javascript_dir
  @javascript_dir
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.



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

def stdout
  @stdout
end

#stylesheet_dirObject (readonly)

Returns the value of attribute stylesheet_dir.



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

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



32
33
34
35
36
37
38
39
40
# File 'lib/install_theme.rb', line 32

def apply_to_target(options = {})
  @stdout = options[:stdout] || @stdout || $stdout
  @inside_yields_originals = {}
  convert_file_to_layout(index_path, 'app/views/layouts/application.html.erb')
  convert_to_haml('app/views/layouts/application.html.erb') if haml?
  prepare_assets
  run_generator(options)
  show_readme
end

#erb?Boolean

Returns:

  • (Boolean)


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

def erb?
  template_type == 'erb'
end

#haml?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/install_theme.rb', line 58

def haml?
  template_type == 'haml'
end

#setup_template_temp_pathObject



50
51
52
53
54
55
56
# File 'lib/install_theme.rb', line 50

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.



44
45
46
47
48
# File 'lib/install_theme.rb', line 44

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