Class: Compass::AppIntegration::Rails::Installer

Inherits:
Installers::ManifestInstaller show all
Defined in:
lib/compass/app_integration/rails/installer.rb

Instance Attribute Summary

Attributes inherited from Installers::ManifestInstaller

#manifest

Attributes inherited from Installers::Base

#options, #target_path, #template_path, #working_path

Attributes included from Compass::Actions

#logger

Instance Method Summary collapse

Methods inherited from Installers::ManifestInstaller

#init, #initialize, #install, #manifest_file

Methods inherited from Installers::Base

#compilation_required?, #initialize, #install, #install_html, #install_html_without_haml, installer, #pattern_name_as_dir, #run, #targetize, #templatize

Methods included from Compass::Actions

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

Constructor Details

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

Instance Method Details

#completed_configurationObject



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_contentsObject



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

Returns:

  • (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_contentsObject



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

#prepareObject



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_dirObject



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_dirObject



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


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



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