Class: Compass::Installers::RailsInstaller

Inherits:
Base
  • Object
show all
Defined in:
lib/compass/installers/rails.rb

Instance Attribute Summary

Attributes inherited from Base

#manifest, #options, #target_path, #template_path, #working_path

Attributes included from Actions

#logger

Instance Method Summary collapse

Methods inherited from Base

#compilation_required?, #configure_option_with_default, #initialize, #install, installer, #manifest_file, #run, #targetize, #templatize

Methods included from Actions

#basename, #compile, #copy, #directory, #relativize, #separate, #strip_trailing_separator, #write_file

Constructor Details

This class inherits a constructor from Compass::Installers::Base

Instance Method Details

#configureObject



6
7
8
9
10
11
12
13
# File 'lib/compass/installers/rails.rb', line 6

def configure
  configuration_file = targetize('config/initializers/compass.rb')
  if File.exists?(configuration_file)
    open(configuration_file) do |config|
      eval(config.read, nil, configuration_file)
    end
  end
end

#css_dirObject



47
48
49
# File 'lib/compass/installers/rails.rb', line 47

def css_dir
  Compass.configuration.css_dir
end

#finalize(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/compass/installers/rails.rb', line 26

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!

Next add these lines to the head of your layouts:

NEXTSTEPS
  end
  puts stylesheet_links
  puts "\n(You are using haml, aren't you?)"
end

#images_dirObject



51
52
53
# File 'lib/compass/installers/rails.rb', line 51

def images_dir
  separate "public/images"
end

#initObject



15
16
17
18
19
20
21
# File 'lib/compass/installers/rails.rb', line 15

def init
  set_sass_dir unless sass_dir
  set_css_dir unless css_dir
  directory targetize(css_dir)
  directory targetize(sass_dir)
  write_file targetize('config/initializers/compass.rb'), initializer_contents
end

#initializer_contentsObject



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/compass/installers/rails.rb', line 81

def initializer_contents
  %Q{require 'compass'
# If you have any compass plugins, require them here.
Compass.configuration do |config|
  config.project_path = RAILS_ROOT
  config.sass_dir = "#{sass_dir}"
  config.css_dir = "#{css_dir}"
end
Compass.configure_sass_plugin!
}
end

#javascripts_dirObject



55
56
57
# File 'lib/compass/installers/rails.rb', line 55

def javascripts_dir
  separate "public/javascripts"
end

#prepareObject



23
24
# File 'lib/compass/installers/rails.rb', line 23

def prepare
end

#sass_dirObject



43
44
45
# File 'lib/compass/installers/rails.rb', line 43

def sass_dir
  Compass.configuration.sass_dir
end

#set_css_dirObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/compass/installers/rails.rb', line 69

def set_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]
  Compass.configuration.css_dir = answer == ?n ? default_location : recommended_location
end

#set_sass_dirObject



59
60
61
62
63
64
65
66
67
# File 'lib/compass/installers/rails.rb', line 59

def set_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]
  Compass.configuration.sass_dir = answer == ?n ? default_location : recommended_location
end


101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/compass/installers/rails.rb', line 101

def stylesheet_links
  html = "%head\n"
  manifest.each_stylesheet do |stylesheet|
    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[:ie]
      ss_line = "  /[if IE]\n  " + ss_line
    end
    html << ss_line + "\n"
  end
  html
end

#stylesheet_prefixObject



93
94
95
96
97
98
99
# File 'lib/compass/installers/rails.rb', line 93

def stylesheet_prefix
  if css_dir.length >= 19
    "#{css_dir[19..-1]}/"
  else
    nil
  end
end