Class: Compass::Commands::InstallRails
- Inherits:
-
Base
- Object
- Base
- Compass::Commands::InstallRails
show all
- Defined in:
- lib/compass/commands/install_rails.rb
Instance Attribute Summary
Attributes inherited from Base
#options, #working_directory
Instance Method Summary
collapse
Constructor Details
#initialize(working_directory, options) ⇒ InstallRails
Returns a new instance of InstallRails.
6
7
8
|
# File 'lib/compass/commands/install_rails.rb', line 6
def initialize(working_directory, options)
super(working_directory, options)
end
|
Instance Method Details
#application_layout_contents ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/compass/commands/install_rails.rb', line 52
def application_layout_contents
%Q{!!! XML
!!!
%html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en"}
%head
%meta{'http-equiv' => "content-type", :content => "text/html;charset=UTF-8"}
%title= @browser_title || 'Default Browser Title'
= stylesheet_link_tag '#{stylesheet_prefix}screen.css', :media => 'screen, projection'
= stylesheet_link_tag '#{stylesheet_prefix}print.css', :media => 'print'
/[if IE]
= stylesheet_link_tag '#{stylesheet_prefix}ie.css', :media => 'screen, projection'
%body
%h1 Welcome to Compass
= yield
}
end
|
#has_application_layout? ⇒ Boolean
85
86
87
88
89
|
# File 'lib/compass/commands/install_rails.rb', line 85
def has_application_layout?
File.exists?(projectize('app/views/layouts/application.rhtml')) ||
File.exists?(projectize('app/views/layouts/application.html.erb')) ||
File.exists?(projectize('app/views/layouts/application.html.haml'))
end
|
#initializer ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/compass/commands/install_rails.rb', line 24
def initializer
init_file =
if File.exists?(init_file) && !options[:force]
msg = "File #{basename(init_file)} already exists. Run with --force to force project creation."
raise ::Compass::Exec::ExecError.new(msg)
end
if File.exists?(init_file)
print_action :overwrite, basename(init_file)
else
print_action :create, basename(init_file)
end
output = open(init_file,'w')
output.write(initializer_contents)
output.close
end
|
#initializer_contents ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/compass/commands/install_rails.rb', line 40
def initializer_contents
%Q{require 'compass'
# If you have any compass plugins, require them here.
Sass::Plugin.options[:template_location] = {
"\#{RAILS_ROOT}#{File::SEPARATOR}#{options[:stylesheets_location]}" => "\#{RAILS_ROOT}#{File::SEPARATOR}#{options[:css_location]}"
}
Compass::Frameworks::ALL.each do |framework|
Sass::Plugin.options[:template_location][framework.stylesheets_directory] = "\#{RAILS_ROOT}#{File::SEPARATOR}#{options[:css_location]}"
end
}
end
|
#next_steps ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/compass/commands/install_rails.rb', line 69
def next_steps
puts <<NEXTSTEPS
Congratulations! Your project has been configured to use Compass.
Next add these lines to the head of your application.html.haml:
%head
= stylesheet_link_tag '#{stylesheet_prefix}screen.css', :media => 'screen, projection'
= stylesheet_link_tag '#{stylesheet_prefix}print.css', :media => 'print'
/[if IE]
= stylesheet_link_tag '#{stylesheet_prefix}ie.css', :media => 'screen, projection'
(you are using haml, aren't you?)
NEXTSTEPS
end
|
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/compass/commands/install_rails.rb', line 9
def perform
set_install_location
set_output_location
directory options[:stylesheets_location]
template 'project/screen.sass', "#{options[:stylesheets_location]}/screen.sass", options
template 'project/print.sass', "#{options[:stylesheets_location]}/print.sass", options
template 'project/ie.sass', "#{options[:stylesheets_location]}/ie.sass", options
write_file projectize('config/initializers/compass.rb'), initializer_contents
if has_application_layout?
next_steps
else
write_file projectize('app/views/layouts/application.html.haml'), application_layout_contents
end
end
|
#project_directory ⇒ Object
99
100
101
|
# File 'lib/compass/commands/install_rails.rb', line 99
def project_directory
working_directory
end
|
#set_install_location ⇒ Object
103
104
105
106
107
|
# File 'lib/compass/commands/install_rails.rb', line 103
def set_install_location
print "Compass recommends that you keep your stylesheets in app/stylesheets/ instead of the Sass default location of public/stylesheets/sass/.\nIs this OK? (Y/n) "
answer = gets
self.options[:stylesheets_location] = separate(answer.downcase[0] == ?n ? 'public/stylesheets/sass' : 'app/stylesheets')
end
|
#set_output_location ⇒ Object
108
109
110
111
112
|
# File 'lib/compass/commands/install_rails.rb', line 108
def set_output_location
print "\nCompass recommends that you keep your compiled css in public/stylesheets/compiled/ instead the Sass default of public/stylesheets/.\nHowever, if you're exclusively using Sass, then public/stylesheets/ is recommended.\nEmit compiled stylesheets to public/stylesheets/compiled? (Y/n) "
answer = gets
self.options[:css_location] = separate(answer.downcase[0] == ?n ? 'public/stylesheets' : 'public/stylesheets/compiled')
end
|
#stylesheet_prefix ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/compass/commands/install_rails.rb', line 91
def stylesheet_prefix
if options[:css_location].length >= 19
"#{options[:css_location][19..-1]}/"
else
nil
end
end
|