Class: Compass::AppIntegration::Rails::Installer
Instance Attribute Summary
#manifest
#options, #target_path, #template_path, #working_path
#logger
Instance Method Summary
collapse
#init, #initialize, #install, #manifest_file
#compilation_required?, #initialize, #install, #install_html, #install_html_without_haml, installer, #pattern_name_as_dir, #run, #targetize, #templatize
#basename, #compile, #copy, #directory, #process_erb, #relativize, #remove, #separate, #strip_trailing_separator, #write_file
Instance Method Details
#completed_configuration ⇒ Object
13
14
15
16
17
18
|
# File 'lib/compass/app_integration/rails/installer.rb', line 13
def completed_configuration
config = {}
config[:sass_dir] = prompt_sass_dir unless sass_dir_without_default
config[:css_dir] = prompt_css_dir unless css_dir_without_default
config unless config.empty?
end
|
#config_contents ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'lib/compass/app_integration/rails/installer.rb', line 81
def config_contents
Compass.configuration.serialize do |prop, value|
if prop == :project_path
"project_path = RAILS_ROOT if defined?(RAILS_ROOT)\n"
elsif prop == :output_style
""
end
end
end
|
#config_files_exist? ⇒ Boolean
28
29
30
31
|
# File 'lib/compass/app_integration/rails/installer.rb', line 28
def config_files_exist?
File.exists?(targetize('config/compass.config')) &&
File.exists?(targetize('config/initializers/compass.rb'))
end
|
#finalize(options = {}) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/compass/app_integration/rails/installer.rb', line 37
def finalize(options = {})
if options[:create]
puts <<-NEXTSTEPS
Congratulations! Your rails project has been configured to use Compass.
Sass will automatically compile your stylesheets during the next
page request and keep them up to date when they change.
Make sure you restart your server!
NEXTSTEPS
end
if manifest.has_stylesheet?
puts "\nNext add these lines to the head of your layouts:\n\n"
puts stylesheet_links
puts "\n(You are using haml, aren't you?)"
end
end
|
#initializer_contents ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'lib/compass/app_integration/rails/installer.rb', line 91
def initializer_contents
%Q{require 'compass'
# If you have any compass plugins, require them here.
Compass.configuration.parse(File.join(RAILS_ROOT, "config", "compass.config"))
Compass.configuration.environment = RAILS_ENV.to_sym
Compass.configure_sass_plugin!
}
end
|
#install_location_for_html(to, options) ⇒ Object
55
56
57
|
# File 'lib/compass/app_integration/rails/installer.rb', line 55
def install_location_for_html(to, options)
separate("public/#{pattern_name_as_dir}#{to}")
end
|
#prepare ⇒ Object
33
34
35
|
# File 'lib/compass/app_integration/rails/installer.rb', line 33
def prepare
write_configuration_files unless config_files_exist?
end
|
#prompt_css_dir ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/compass/app_integration/rails/installer.rb', line 69
def prompt_css_dir
recommended_location = separate("public/stylesheets/compiled")
default_location = separate("public/stylesheets")
puts
print %Q{Compass recommends that you keep your compiled css in #{recommended_location}/
instead the Sass default of #{default_location}/.
However, if you're exclusively using Sass, then #{default_location}/ is recommended.
Emit compiled stylesheets to #{recommended_location}/? (Y/n) }
answer = gets.downcase[0]
answer == ?n ? default_location : recommended_location
end
|
#prompt_sass_dir ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/compass/app_integration/rails/installer.rb', line 59
def prompt_sass_dir
recommended_location = separate('app/stylesheets')
default_location = separate('public/stylesheets/sass')
print %Q{Compass recommends that you keep your stylesheets in #{recommended_location}
instead of the Sass default location of #{default_location}.
Is this OK? (Y/n) }
answer = gets.downcase[0]
answer == ?n ? default_location : recommended_location
end
|
#stylesheet_links ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/compass/app_integration/rails/installer.rb', line 108
def stylesheet_links
html = "%head\n"
manifest.each_stylesheet do |stylesheet|
next if File.basename(stylesheet.from)[0..0] == "_"
ss_line = " = stylesheet_link_tag '#{stylesheet_prefix}#{stylesheet.to.sub(/\.sass$/,'.css')}'"
if stylesheet.options[:media]
ss_line += ", :media => '#{stylesheet.options[:media]}'"
end
if stylesheet.options[:condition]
ss_line = " /[if #{stylesheet.options[:condition]}]\n " + ss_line
end
html << ss_line + "\n"
end
html
end
|
#stylesheet_prefix ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/compass/app_integration/rails/installer.rb', line 100
def stylesheet_prefix
if css_dir.length >= 19
"#{css_dir[19..-1]}/"
else
nil
end
end
|
#write_configuration_files(config_file = nil) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/compass/app_integration/rails/installer.rb', line 20
def write_configuration_files(config_file = nil)
config_file ||= targetize('config/compass.rb')
directory File.dirname(config_file)
write_file config_file, config_contents
directory File.dirname(targetize('config/initializers/compass.rb'))
write_file targetize('config/initializers/compass.rb'), initializer_contents
end
|