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, #init, #initialize, #install, installer, #manifest_file, #pattern_name_as_dir, #run, #targetize, #templatize

Methods included from Actions

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

Constructor Details

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

Instance Method Details

#config_contentsObject



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

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

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/compass/installers/rails.rb', line 24

def config_files_exist?
  File.exists?(targetize('config/compass.config')) &&
  File.exists?(targetize('config/initializers/compass.rb'))
end

#configuration_defaultsObject



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

def configuration_defaults
  {
    :sass_dir => (sass_dir || prompt_sass_dir),
    :css_dir => (css_dir || prompt_css_dir),
    :images_dir => default_images_dir,
    :javascripts_dir => default_javascripts_dir,
    :http_stylesheets_path => default_http_stylesheets_path,
    :http_javascripts_path => default_http_javascripts_path,
    :http_images_path => default_http_images_path
  }
end

#default_http_images_pathObject



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

def default_http_images_path
  "/images"
end

#default_http_javascripts_pathObject



60
61
62
# File 'lib/compass/installers/rails.rb', line 60

def default_http_javascripts_path
  "/javascripts"
end

#default_http_stylesheets_pathObject



64
65
66
# File 'lib/compass/installers/rails.rb', line 64

def default_http_stylesheets_path
  "/stylesheets"
end

#default_images_dirObject



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

def default_images_dir
  separate("public/images")
end

#default_javascripts_dirObject



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

def default_javascripts_dir
  separate("public/javascripts")
end

#finalize(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/compass/installers/rails.rb', line 33

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

#initializer_contentsObject



100
101
102
103
104
105
106
107
# File 'lib/compass/installers/rails.rb', line 100

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

#prepareObject



29
30
31
# File 'lib/compass/installers/rails.rb', line 29

def prepare
  write_configuration_files unless config_files_exist?
end

#prompt_css_dirObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/compass/installers/rails.rb', line 78

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_dirObject



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

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


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/compass/installers/rails.rb', line 117

def stylesheet_links
  html = "%head\n"
  manifest.each_stylesheet do |stylesheet|
    # Skip partials.
    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_prefixObject



109
110
111
112
113
114
115
# File 'lib/compass/installers/rails.rb', line 109

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

#write_configuration_files(config_file = nil) ⇒ Object



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

def write_configuration_files(config_file = nil)
  config_file ||= targetize('config/compass.config')
  write_file config_file, config_contents
  write_file targetize('config/initializers/compass.rb'), initializer_contents
end