jsmestad-compass 0.4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +175 -0
- data/README.markdown +17 -0
- data/Rakefile +125 -0
- data/VERSION +1 -0
- data/bin/compass +8 -0
- data/compass.gemspec +37 -0
- data/examples/blueprint_default/index.html +73 -0
- data/examples/blueprint_default/parts/elements.html +246 -0
- data/examples/blueprint_default/parts/forms.html +100 -0
- data/examples/blueprint_default/parts/grid.html +206 -0
- data/examples/blueprint_default/parts/test-small.jpg +0 -0
- data/examples/blueprint_default/parts/test.jpg +0 -0
- data/examples/blueprint_default/parts/valid.png +0 -0
- data/examples/blueprint_default/stylesheets/ie.sass +3 -0
- data/examples/blueprint_default/stylesheets/images/grid.png +0 -0
- data/examples/blueprint_default/stylesheets/print.sass +3 -0
- data/examples/blueprint_default/stylesheets/screen.sass +8 -0
- data/examples/blueprint_plugins/index.html +60 -0
- data/examples/blueprint_plugins/parts/fancy_type.html +84 -0
- data/examples/blueprint_plugins/parts/test-small.jpg +0 -0
- data/examples/blueprint_plugins/parts/test.jpg +0 -0
- data/examples/blueprint_plugins/parts/valid.png +0 -0
- data/examples/blueprint_plugins/stylesheets/ie.sass +3 -0
- data/examples/blueprint_plugins/stylesheets/images/grid.png +0 -0
- data/examples/blueprint_plugins/stylesheets/print.sass +3 -0
- data/examples/blueprint_plugins/stylesheets/screen.sass +11 -0
- data/examples/blueprint_scoped/stylesheets/ie.sass +3 -0
- data/examples/blueprint_scoped/stylesheets/print.sass +3 -0
- data/examples/blueprint_scoped/stylesheets/screen.sass +4 -0
- data/examples/blueprint_scoped_form/stylesheets/ie.sass +3 -0
- data/examples/blueprint_scoped_form/stylesheets/print.sass +3 -0
- data/examples/blueprint_scoped_form/stylesheets/screen.sass +10 -0
- data/examples/blueprint_semantic/index.html +68 -0
- data/examples/blueprint_semantic/parts/fancy_type.html +84 -0
- data/examples/blueprint_semantic/parts/liquid.html +84 -0
- data/examples/blueprint_semantic/parts/test-small.jpg +0 -0
- data/examples/blueprint_semantic/parts/test.jpg +0 -0
- data/examples/blueprint_semantic/parts/valid.png +0 -0
- data/examples/blueprint_semantic/stylesheets/ie.sass +3 -0
- data/examples/blueprint_semantic/stylesheets/images/grid.png +0 -0
- data/examples/blueprint_semantic/stylesheets/liquid.sass +70 -0
- data/examples/blueprint_semantic/stylesheets/print.sass +3 -0
- data/examples/blueprint_semantic/stylesheets/screen.sass +69 -0
- data/examples/compass/compass.html +19 -0
- data/examples/compass/sticky_footer.html.haml +14 -0
- data/examples/compass/stylesheets/compass.sass +47 -0
- data/examples/compass/stylesheets/images/blue_arrow.gif +0 -0
- data/examples/compass/stylesheets/sticky_footer.sass +11 -0
- data/examples/compass/stylesheets/utilities.sass +65 -0
- data/examples/compass/utilities.html.haml +136 -0
- data/examples/yui/divisions.html.haml +179 -0
- data/examples/yui/index.html.haml +19 -0
- data/examples/yui/stylesheets/screen.sass +13 -0
- data/examples/yui/sub_divisions.html.haml +169 -0
- data/examples/yui/templates.html.haml +54 -0
- data/examples/yui/test.jpg +0 -0
- data/examples/yui/typography.html.haml +132 -0
- data/frameworks/blueprint.rb +2 -0
- data/frameworks/blueprint/lib/blueprint/constants.rb +17 -0
- data/frameworks/blueprint/lib/blueprint/grid_builder.rb +54 -0
- data/frameworks/blueprint/stylesheets/_blueprint.sass +3 -0
- data/frameworks/blueprint/stylesheets/blueprint/_ie.sass +49 -0
- data/frameworks/blueprint/stylesheets/blueprint/_print.sass +82 -0
- data/frameworks/blueprint/stylesheets/blueprint/_screen.sass +15 -0
- data/frameworks/blueprint/stylesheets/blueprint/modules/_colors.sass +30 -0
- data/frameworks/blueprint/stylesheets/blueprint/modules/_debug.sass +9 -0
- data/frameworks/blueprint/stylesheets/blueprint/modules/_fancy_type.sass +81 -0
- data/frameworks/blueprint/stylesheets/blueprint/modules/_form.sass +43 -0
- data/frameworks/blueprint/stylesheets/blueprint/modules/_grid.sass +141 -0
- data/frameworks/blueprint/stylesheets/blueprint/modules/_interaction.sass +58 -0
- data/frameworks/blueprint/stylesheets/blueprint/modules/_liquid.sass +137 -0
- data/frameworks/blueprint/stylesheets/blueprint/modules/_scaffolding.sass +46 -0
- data/frameworks/blueprint/stylesheets/blueprint/modules/_typography.sass +153 -0
- data/frameworks/blueprint/stylesheets/blueprint/modules/_utilities.sass +37 -0
- data/frameworks/blueprint/templates/project/grid.png +0 -0
- data/frameworks/blueprint/templates/project/ie.sass +3 -0
- data/frameworks/blueprint/templates/project/manifest.rb +5 -0
- data/frameworks/blueprint/templates/project/print.sass +3 -0
- data/frameworks/blueprint/templates/project/screen.sass +8 -0
- data/frameworks/compass.rb +2 -0
- data/frameworks/compass/stylesheets/_compass.sass +1 -0
- data/frameworks/compass/stylesheets/compass/_layout.sass +1 -0
- data/frameworks/compass/stylesheets/compass/_reset.sass +3 -0
- data/frameworks/compass/stylesheets/compass/_utilities.sass +5 -0
- data/frameworks/compass/stylesheets/compass/layout/_sticky_footer.sass +17 -0
- data/frameworks/compass/stylesheets/compass/utilities/_general.sass +4 -0
- data/frameworks/compass/stylesheets/compass/utilities/_links.sass +3 -0
- data/frameworks/compass/stylesheets/compass/utilities/_lists.sass +3 -0
- data/frameworks/compass/stylesheets/compass/utilities/_print.sass +24 -0
- data/frameworks/compass/stylesheets/compass/utilities/_tables.sass +1 -0
- data/frameworks/compass/stylesheets/compass/utilities/_text.sass +2 -0
- data/frameworks/compass/stylesheets/compass/utilities/general/_clearfix.sass +11 -0
- data/frameworks/compass/stylesheets/compass/utilities/general/_inline_block.sass +6 -0
- data/frameworks/compass/stylesheets/compass/utilities/general/_reset.sass +58 -0
- data/frameworks/compass/stylesheets/compass/utilities/general/_tabs.sass +0 -0
- data/frameworks/compass/stylesheets/compass/utilities/general/_tag_cloud.sass +19 -0
- data/frameworks/compass/stylesheets/compass/utilities/links/_hover_link.sass +5 -0
- data/frameworks/compass/stylesheets/compass/utilities/links/_link_colors.sass +24 -0
- data/frameworks/compass/stylesheets/compass/utilities/links/_unstyled_link.sass +5 -0
- data/frameworks/compass/stylesheets/compass/utilities/lists/_bullets.sass +21 -0
- data/frameworks/compass/stylesheets/compass/utilities/lists/_horizontal_list.sass +20 -0
- data/frameworks/compass/stylesheets/compass/utilities/lists/_inline_list.sass +29 -0
- data/frameworks/compass/stylesheets/compass/utilities/tables/_alternating_rows_and_columns.sass +25 -0
- data/frameworks/compass/stylesheets/compass/utilities/text/_nowrap.sass +3 -0
- data/frameworks/compass/stylesheets/compass/utilities/text/_replacement.sass +10 -0
- data/frameworks/compass/templates/project/ie.sass +6 -0
- data/frameworks/compass/templates/project/manifest.rb +3 -0
- data/frameworks/compass/templates/project/print.sass +6 -0
- data/frameworks/compass/templates/project/screen.sass +7 -0
- data/frameworks/yui.rb +2 -0
- data/frameworks/yui/COPYRIGHT +15 -0
- data/frameworks/yui/stylesheets/_yui.sass +7 -0
- data/frameworks/yui/stylesheets/yui/modules/_base.sass +60 -0
- data/frameworks/yui/stylesheets/yui/modules/_fonts.sass +38 -0
- data/frameworks/yui/stylesheets/yui/modules/_grids.sass +341 -0
- data/frameworks/yui/templates/project/manifest.rb +1 -0
- data/frameworks/yui/templates/project/screen.sass +4 -0
- data/lib/compass.rb +39 -0
- data/lib/compass/actions.rb +92 -0
- data/lib/compass/commands/base.rb +26 -0
- data/lib/compass/commands/create_project.rb +41 -0
- data/lib/compass/commands/list_frameworks.rb +16 -0
- data/lib/compass/commands/print_version.rb +23 -0
- data/lib/compass/commands/project_base.rb +74 -0
- data/lib/compass/commands/update_project.rb +61 -0
- data/lib/compass/commands/watch_project.rb +53 -0
- data/lib/compass/compiler.rb +40 -0
- data/lib/compass/configuration.rb +92 -0
- data/lib/compass/core_ext.rb +12 -0
- data/lib/compass/errors.rb +7 -0
- data/lib/compass/exec.rb +184 -0
- data/lib/compass/frameworks.rb +29 -0
- data/lib/compass/installers.rb +5 -0
- data/lib/compass/installers/base.rb +135 -0
- data/lib/compass/installers/manifest.rb +57 -0
- data/lib/compass/installers/rails.rb +125 -0
- data/lib/compass/installers/stand_alone.rb +76 -0
- data/lib/compass/logger.rb +34 -0
- data/lib/compass/merb.rb +43 -0
- data/lib/compass/test_case.rb +37 -0
- data/lib/compass/validate.rb +13 -0
- data/lib/compass/validate/COPYRIGHT.html +93 -0
- data/lib/compass/validate/JIGSAW_COPYRIGHT +64 -0
- data/lib/compass/validate/README.html +83 -0
- data/lib/compass/validate/XERCES_COPYING.txt +56 -0
- data/lib/compass/validate/css-validator-javadoc.jar +0 -0
- data/lib/compass/validate/css-validator.jar +0 -0
- data/lib/compass/validate/jigsaw.jar +0 -0
- data/lib/compass/validate/xerces.jar +0 -0
- data/lib/compass/validator.rb +59 -0
- data/lib/compass/version.rb +66 -0
- data/lib/sass_extensions.rb +13 -0
- data/test/command_line_test.rb +147 -0
- data/test/compass_test.rb +148 -0
- data/test/configuration_test.rb +28 -0
- data/test/fixtures/stylesheets/blueprint/css/typography.css +158 -0
- data/test/fixtures/stylesheets/blueprint/sass/ie.sass +3 -0
- data/test/fixtures/stylesheets/blueprint/sass/print.sass +3 -0
- data/test/fixtures/stylesheets/blueprint/sass/screen.sass +17 -0
- data/test/fixtures/stylesheets/blueprint/sass/typography.sass +3 -0
- data/test/fixtures/stylesheets/compass/css/layout.css +14 -0
- data/test/fixtures/stylesheets/compass/css/print.css +19 -0
- data/test/fixtures/stylesheets/compass/css/reset.css +69 -0
- data/test/fixtures/stylesheets/compass/css/utilities.css +21 -0
- data/test/fixtures/stylesheets/compass/sass/layout.sass +3 -0
- data/test/fixtures/stylesheets/compass/sass/print.sass +5 -0
- data/test/fixtures/stylesheets/compass/sass/reset.sass +1 -0
- data/test/fixtures/stylesheets/compass/sass/utilities.sass +5 -0
- data/test/fixtures/stylesheets/yui/css/mixins.css +16 -0
- data/test/fixtures/stylesheets/yui/sass/base.sass +3 -0
- data/test/fixtures/stylesheets/yui/sass/fonts.sass +3 -0
- data/test/fixtures/stylesheets/yui/sass/grids.sass +3 -0
- data/test/fixtures/stylesheets/yui/sass/mixins.sass +16 -0
- data/test/sass_extensions_test.rb +26 -0
- data/test/test_helper.rb +47 -0
- metadata +291 -0
data/lib/compass/exec.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'haml'
|
4
|
+
require File.join(Compass.lib_directory, 'compass', 'logger')
|
5
|
+
require File.join(Compass.lib_directory, 'compass', 'errors')
|
6
|
+
require File.join(Compass.lib_directory, 'compass', 'actions')
|
7
|
+
|
8
|
+
module Compass
|
9
|
+
module Exec
|
10
|
+
|
11
|
+
def report_error(e, options)
|
12
|
+
$stderr.puts "#{e.class} on line #{get_line e} of #{get_file e}: #{e.message}"
|
13
|
+
if options[:trace]
|
14
|
+
e.backtrace[1..-1].each { |t| $stderr.puts " #{t}" }
|
15
|
+
else
|
16
|
+
$stderr.puts "Run with --trace to see the full backtrace"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_file(exception)
|
21
|
+
exception.backtrace[0].split(/:/, 2)[0]
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_line(exception)
|
25
|
+
# SyntaxErrors have weird line reporting
|
26
|
+
# when there's trailing whitespace,
|
27
|
+
# which there is for Haml documents.
|
28
|
+
return exception.message.scan(/:(\d+)/)[0] if exception.is_a?(::Haml::SyntaxError)
|
29
|
+
exception.backtrace[0].scan(/:(\d+)/)[0]
|
30
|
+
end
|
31
|
+
module_function :report_error, :get_file, :get_line
|
32
|
+
|
33
|
+
class Compass
|
34
|
+
|
35
|
+
attr_accessor :args, :options, :opts
|
36
|
+
|
37
|
+
def initialize(args)
|
38
|
+
self.args = args
|
39
|
+
self.options = {}
|
40
|
+
parse!
|
41
|
+
end
|
42
|
+
|
43
|
+
def run!
|
44
|
+
begin
|
45
|
+
perform!
|
46
|
+
rescue Exception => e
|
47
|
+
raise e if e.is_a? SystemExit
|
48
|
+
if e.is_a?(::Compass::Error) || e.is_a?(OptionParser::ParseError)
|
49
|
+
$stderr.puts e.message
|
50
|
+
else
|
51
|
+
::Compass::Exec.report_error(e, @options)
|
52
|
+
end
|
53
|
+
return 1
|
54
|
+
end
|
55
|
+
return 0
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def perform!
|
61
|
+
if options[:command]
|
62
|
+
do_command(options[:command])
|
63
|
+
else
|
64
|
+
puts self.opts
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse!
|
69
|
+
self.opts = OptionParser.new(&method(:set_opts))
|
70
|
+
self.opts.parse!(self.args)
|
71
|
+
if self.args.size > 0
|
72
|
+
self.options[:project_name] = trim_trailing_separator(self.args.shift)
|
73
|
+
end
|
74
|
+
self.options[:command] ||= self.options[:project_name] ? :create_project : :update_project
|
75
|
+
self.options[:environment] ||= :production
|
76
|
+
self.options[:framework] ||= :compass
|
77
|
+
self.options[:project_type] ||= :stand_alone
|
78
|
+
end
|
79
|
+
|
80
|
+
def trim_trailing_separator(path)
|
81
|
+
path[-1..-1] == File::SEPARATOR ? path[0..-2] : path
|
82
|
+
end
|
83
|
+
|
84
|
+
def set_opts(opts)
|
85
|
+
opts.banner = <<END
|
86
|
+
Usage: compass [options] [project]
|
87
|
+
|
88
|
+
Description:
|
89
|
+
When project is given, generates a new project of that name as a subdirectory of
|
90
|
+
the current directory.
|
91
|
+
|
92
|
+
If you change any source files, you can update your project using --update.
|
93
|
+
|
94
|
+
Options:
|
95
|
+
END
|
96
|
+
opts.on('-u', '--update', :NONE, 'Update the current project') do
|
97
|
+
self.options[:command] = :update_project
|
98
|
+
end
|
99
|
+
|
100
|
+
opts.on('-w', '--watch', :NONE, 'Monitor the current project for changes and update') do
|
101
|
+
self.options[:command] = :watch_project
|
102
|
+
end
|
103
|
+
|
104
|
+
opts.on('--source SRC_DIR', "The source directory (where you keep your sass stylesheets).") do |src_dir|
|
105
|
+
self.options[:src_dir] = src_dir
|
106
|
+
end
|
107
|
+
|
108
|
+
opts.on('--target CSS_DIR', "The target directory (where you keep your css stylesheets).") do |css_dir|
|
109
|
+
self.options[:css_dir] = css_dir
|
110
|
+
end
|
111
|
+
|
112
|
+
opts.on('--list-frameworks', "List compass frameworks available to use.") do
|
113
|
+
self.options[:command] = :list_frameworks
|
114
|
+
end
|
115
|
+
|
116
|
+
opts.on('-f FRAMEWORK', '--framework FRAMEWORK', 'Set up a new project using the selected framework. Legal values: compass (default), blueprint') do |framework|
|
117
|
+
self.options[:framework] = framework
|
118
|
+
end
|
119
|
+
|
120
|
+
opts.on('-e ENV', '--environment ENV', [:development, :production], 'Use sensible defaults for your current environment: development, production (default)') do |env|
|
121
|
+
self.options[:environment] = env
|
122
|
+
end
|
123
|
+
|
124
|
+
opts.on('-s STYLE', '--output-style STYLE', [:nested, :expanded, :compact, :compressed], 'Select a CSS output mode (nested, expanded, compact, compressed)') do |style|
|
125
|
+
self.options[:style] = style
|
126
|
+
end
|
127
|
+
|
128
|
+
opts.on('-r LIBRARY', '--require LIBRARY', "Require LIBRARY before running commands. This is used to access compass plugins.") do |library|
|
129
|
+
require library
|
130
|
+
end
|
131
|
+
|
132
|
+
opts.on('-y', "Answers yes to normall asked generator questions. Designed for rails-templates.") do
|
133
|
+
self.options[:answer_yes] = true
|
134
|
+
end
|
135
|
+
|
136
|
+
opts.on('--rails', "Sets the project type to a rails project.") do
|
137
|
+
self.options[:project_type] = :rails
|
138
|
+
end
|
139
|
+
|
140
|
+
opts.on('-q', '--quiet', :NONE, 'Quiet mode.') do
|
141
|
+
self.options[:quiet] = true
|
142
|
+
end
|
143
|
+
|
144
|
+
opts.on('--dry-run', :NONE, 'Dry Run. Tells you what it plans to do.') do
|
145
|
+
self.options[:dry_run] = true
|
146
|
+
end
|
147
|
+
|
148
|
+
opts.on('--trace', :NONE, 'Show a full traceback on error') do
|
149
|
+
self.options[:trace] = true
|
150
|
+
end
|
151
|
+
|
152
|
+
opts.on('--force', :NONE, 'Force. Allows some commands to succeed when they would otherwise fail.') do
|
153
|
+
self.options[:force] = true
|
154
|
+
end
|
155
|
+
|
156
|
+
opts.on('--imports', :NONE, 'Emit an import path suitable for use with the Sass command-line tool.') do
|
157
|
+
#XXX cross platform support?
|
158
|
+
print ::Compass::Frameworks::ALL.map{|f| "-I #{f.stylesheets_directory}"}.join(' ')
|
159
|
+
exit
|
160
|
+
end
|
161
|
+
|
162
|
+
opts.on_tail("-?", "-h", "--help", "Show this message") do
|
163
|
+
puts opts
|
164
|
+
exit
|
165
|
+
end
|
166
|
+
|
167
|
+
opts.on_tail("-v", "--version", "Print version") do
|
168
|
+
self.options[:command] = :print_version
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def do_command(command)
|
173
|
+
command_class_name = command.to_s.split(/_/).map{|p| p.capitalize}.join('')
|
174
|
+
command_class = eval("::Compass::Commands::#{command_class_name}")
|
175
|
+
command_class.new(Dir.getwd, options).perform
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'commands', "*.rb")).each do |file|
|
183
|
+
require file
|
184
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Compass
|
2
|
+
module Frameworks
|
3
|
+
ALL = []
|
4
|
+
class Framework
|
5
|
+
attr_accessor :name
|
6
|
+
attr_accessor :templates_directory, :stylesheets_directory
|
7
|
+
def initialize(name, *arguments)
|
8
|
+
options = arguments.last.is_a?(Hash) ? arguments.pop : {}
|
9
|
+
path = options[:path] || arguments.shift
|
10
|
+
@name = name
|
11
|
+
@templates_directory = options[:templates_directory] || File.join(path, 'templates')
|
12
|
+
@stylesheets_directory = options[:stylesheets_directory] || File.join(path, 'stylesheets')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
def register(name, *arguments)
|
16
|
+
ALL << Framework.new(name, *arguments)
|
17
|
+
end
|
18
|
+
def [](name)
|
19
|
+
ALL.detect{|f| f.name.to_s == name.to_s}
|
20
|
+
end
|
21
|
+
module_function :register, :[]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Import all of the default frameworks.
|
26
|
+
default_frameworks_directory = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'frameworks'))
|
27
|
+
Dir.glob(File.join(default_frameworks_directory, "*.rb")).each do |framework|
|
28
|
+
require framework
|
29
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'installers', 'manifest')
|
2
|
+
require File.join(File.dirname(__FILE__), 'installers', 'base')
|
3
|
+
require File.join(File.dirname(__FILE__), 'installers', 'stand_alone')
|
4
|
+
require File.join(File.dirname(__FILE__), 'installers', 'rails')
|
5
|
+
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module Compass
|
2
|
+
module Installers
|
3
|
+
|
4
|
+
class Base
|
5
|
+
|
6
|
+
include Actions
|
7
|
+
|
8
|
+
attr_accessor :template_path, :target_path, :working_path
|
9
|
+
attr_accessor :options
|
10
|
+
attr_accessor :manifest
|
11
|
+
attr_accessor :css_dir, :sass_dir, :images_dir, :javascripts_dir
|
12
|
+
|
13
|
+
def initialize(template_path, target_path, options = {})
|
14
|
+
@template_path = template_path
|
15
|
+
@target_path = target_path
|
16
|
+
@working_path = Dir.getwd
|
17
|
+
@options = options
|
18
|
+
@manifest = Manifest.new(manifest_file)
|
19
|
+
self.logger = options[:logger]
|
20
|
+
configure
|
21
|
+
end
|
22
|
+
|
23
|
+
def manifest_file
|
24
|
+
@manifest_file ||= File.join(template_path, "manifest.rb")
|
25
|
+
end
|
26
|
+
|
27
|
+
# Initializes the project to work with compass
|
28
|
+
def init
|
29
|
+
end
|
30
|
+
|
31
|
+
# Runs the installer.
|
32
|
+
# Every installer must conform to the installation strategy of prepare, install, and then finalize.
|
33
|
+
# A default implementation is provided for each step.
|
34
|
+
def run(options = {})
|
35
|
+
prepare
|
36
|
+
install
|
37
|
+
finalize unless options[:skip_finalization]
|
38
|
+
end
|
39
|
+
|
40
|
+
# The default configure method -- it sets up directories from the options
|
41
|
+
# and corresponding default_* methods for those not found in the options hash.
|
42
|
+
# It can be overridden it or augmented for reading config files,
|
43
|
+
# prompting the user for more information, etc.
|
44
|
+
def configure
|
45
|
+
unless @configured
|
46
|
+
[:css_dir, :sass_dir, :images_dir, :javascripts_dir].each do |opt|
|
47
|
+
configure_option_with_default opt
|
48
|
+
end
|
49
|
+
end
|
50
|
+
ensure
|
51
|
+
@configured = true
|
52
|
+
end
|
53
|
+
|
54
|
+
# The default prepare method -- it is a no-op.
|
55
|
+
# Generally you would create required directories, etc.
|
56
|
+
def prepare
|
57
|
+
end
|
58
|
+
|
59
|
+
def configure_option_with_default(opt)
|
60
|
+
value = options[opt]
|
61
|
+
value ||= begin
|
62
|
+
default_method = "default_#{opt}".to_sym
|
63
|
+
send(default_method) if respond_to?(default_method)
|
64
|
+
end
|
65
|
+
send("#{opt}=", value)
|
66
|
+
end
|
67
|
+
|
68
|
+
# The default install method. Calls install_<type> methods in the order specified by the manifest.
|
69
|
+
def install
|
70
|
+
manifest.each do |entry|
|
71
|
+
send("install_#{entry.type}", entry.from, entry.to, entry.options)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# The default finalize method -- it is a no-op.
|
76
|
+
# This could print out a message or something.
|
77
|
+
def finalize
|
78
|
+
end
|
79
|
+
|
80
|
+
def compilation_required?
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.installer(type, &locator)
|
85
|
+
locator ||= lambda{|to| to}
|
86
|
+
loc_method = "install_location_for_#{type}".to_sym
|
87
|
+
define_method loc_method, locator
|
88
|
+
define_method "install_#{type}" do |from, to, options|
|
89
|
+
copy templatize(from), targetize(send(loc_method, to))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
installer :stylesheet do |to|
|
94
|
+
"#{sass_dir}/#{to}"
|
95
|
+
end
|
96
|
+
|
97
|
+
installer :image do |to|
|
98
|
+
"#{images_dir}/#{to}"
|
99
|
+
end
|
100
|
+
|
101
|
+
installer :script do |to|
|
102
|
+
"#{javascripts_dir}/#{to}"
|
103
|
+
end
|
104
|
+
|
105
|
+
installer :file
|
106
|
+
|
107
|
+
# returns an absolute path given a path relative to the current installation target.
|
108
|
+
# Paths can use unix style "/" and will be corrected for the current platform.
|
109
|
+
def targetize(path)
|
110
|
+
strip_trailing_separator File.join(target_path, separate(path))
|
111
|
+
end
|
112
|
+
|
113
|
+
# returns an absolute path given a path relative to the current template.
|
114
|
+
# Paths can use unix style "/" and will be corrected for the current platform.
|
115
|
+
def templatize(path)
|
116
|
+
strip_trailing_separator File.join(template_path, separate(path))
|
117
|
+
end
|
118
|
+
|
119
|
+
def stylesheet_links
|
120
|
+
html = "<head>\n"
|
121
|
+
manifest.each_stylesheet do |stylesheet|
|
122
|
+
media = if stylesheet.options[:media]
|
123
|
+
%Q{ media="#{stylesheet.options[:media]}"}
|
124
|
+
end
|
125
|
+
ss_line = %Q{ <link href="/stylesheets/#{stylesheet.to.sub(/\.sass$/,'.css')}"#{media} rel="stylesheet" type="text/css" />}
|
126
|
+
if stylesheet.options[:ie]
|
127
|
+
ss_line = " <!--[if IE]>\n #{ss_line}\n <![endif]-->"
|
128
|
+
end
|
129
|
+
html << ss_line + "\n"
|
130
|
+
end
|
131
|
+
html << "</head>"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Compass
|
2
|
+
module Installers
|
3
|
+
|
4
|
+
class Manifest
|
5
|
+
|
6
|
+
# A Manifest entry
|
7
|
+
class Entry < Struct.new(:type, :from, :options)
|
8
|
+
def to
|
9
|
+
options[:to] || from
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(manifest_file = nil)
|
14
|
+
@entries = []
|
15
|
+
parse(manifest_file) if manifest_file
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.type(t)
|
19
|
+
eval <<-END
|
20
|
+
def #{t}(from, options = {})
|
21
|
+
@entries << Entry.new(:#{t}, from, options)
|
22
|
+
end
|
23
|
+
def has_#{t}?
|
24
|
+
@entries.detect {|e| e.type == :#{t}}
|
25
|
+
end
|
26
|
+
def each_#{t}
|
27
|
+
@entries.select {|e| e.type == :#{t}}.each {|e| yield e}
|
28
|
+
end
|
29
|
+
END
|
30
|
+
end
|
31
|
+
|
32
|
+
type :stylesheet
|
33
|
+
type :image
|
34
|
+
type :javascript
|
35
|
+
type :file
|
36
|
+
|
37
|
+
# Enumerates over the manifest files
|
38
|
+
def each
|
39
|
+
@entries.each {|e| yield e}
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
protected
|
44
|
+
# parses a manifest file which is a ruby script
|
45
|
+
# evaluated in a Manifest instance context
|
46
|
+
def parse(manifest_file)
|
47
|
+
open(manifest_file) do |f|
|
48
|
+
eval(f.read, instance_binding, manifest_file)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
def instance_binding
|
52
|
+
binding
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Compass
|
2
|
+
module Installers
|
3
|
+
|
4
|
+
class RailsInstaller < Base
|
5
|
+
|
6
|
+
def configure
|
7
|
+
configuration_file = targetize('config/initializers/compass.rb')
|
8
|
+
if File.exists?(configuration_file)
|
9
|
+
open(configuration_file) do |config|
|
10
|
+
eval(config.read, nil, configuration_file)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def init
|
16
|
+
set_sass_dir unless sass_dir
|
17
|
+
set_css_dir unless css_dir
|
18
|
+
directory targetize(css_dir)
|
19
|
+
directory targetize(sass_dir)
|
20
|
+
write_file targetize('config/initializers/compass.rb'), initializer_contents
|
21
|
+
end
|
22
|
+
|
23
|
+
def prepare
|
24
|
+
end
|
25
|
+
|
26
|
+
def finalize(options = {})
|
27
|
+
if options[:create]
|
28
|
+
puts <<-NEXTSTEPS
|
29
|
+
|
30
|
+
Congratulations! Your rails project has been configured to use Compass.
|
31
|
+
Sass will automatically compile your stylesheets during the next
|
32
|
+
page request and keep them up to date when they change.
|
33
|
+
Make sure you restart your server!
|
34
|
+
|
35
|
+
Next add these lines to the head of your layouts:
|
36
|
+
|
37
|
+
NEXTSTEPS
|
38
|
+
end
|
39
|
+
puts stylesheet_links
|
40
|
+
puts "\n(You are using haml, aren't you?)"
|
41
|
+
end
|
42
|
+
|
43
|
+
def sass_dir
|
44
|
+
Compass.configuration.sass_dir
|
45
|
+
end
|
46
|
+
|
47
|
+
def css_dir
|
48
|
+
Compass.configuration.css_dir
|
49
|
+
end
|
50
|
+
|
51
|
+
def images_dir
|
52
|
+
separate "public/images"
|
53
|
+
end
|
54
|
+
|
55
|
+
def javascripts_dir
|
56
|
+
separate "public/javascripts"
|
57
|
+
end
|
58
|
+
|
59
|
+
def set_sass_dir
|
60
|
+
recommended_location = separate('app/stylesheets')
|
61
|
+
default_location = separate('public/stylesheets/sass')
|
62
|
+
if @options[:answer_yes]
|
63
|
+
Compass.configuration.sass_dir = recommended_location
|
64
|
+
else
|
65
|
+
print %Q{Compass recommends that you keep your stylesheets in #{recommended_location}
|
66
|
+
instead of the Sass default location of #{default_location}.
|
67
|
+
Is this OK? (Y/n) }
|
68
|
+
answer = gets.downcase[0]
|
69
|
+
Compass.configuration.sass_dir = answer == ?n ? default_location : recommended_location
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_css_dir
|
74
|
+
recommended_location = separate("public/stylesheets/compiled")
|
75
|
+
default_location = separate("public/stylesheets")
|
76
|
+
if @options[:answer_yes]
|
77
|
+
Compass.configuration.css_dir = recommended_location
|
78
|
+
else
|
79
|
+
puts
|
80
|
+
print %Q{Compass recommends that you keep your compiled css in #{recommended_location}/
|
81
|
+
instead the Sass default of #{default_location}/.
|
82
|
+
However, if you're exclusively using Sass, then #{default_location}/ is recommended.
|
83
|
+
Emit compiled stylesheets to #{recommended_location}/? (Y/n) }
|
84
|
+
answer = gets.downcase[0]
|
85
|
+
Compass.configuration.css_dir = answer == ?n ? default_location : recommended_location
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def initializer_contents
|
90
|
+
%Q{require 'compass'
|
91
|
+
# If you have any compass plugins, require them here.
|
92
|
+
Compass.configuration do |config|
|
93
|
+
config.project_path = RAILS_ROOT
|
94
|
+
config.sass_dir = "#{sass_dir}"
|
95
|
+
config.css_dir = "#{css_dir}"
|
96
|
+
end
|
97
|
+
Compass.configure_sass_plugin!
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
def stylesheet_prefix
|
102
|
+
if css_dir.length >= 19
|
103
|
+
"#{css_dir[19..-1]}/"
|
104
|
+
else
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def stylesheet_links
|
110
|
+
html = "%head\n"
|
111
|
+
manifest.each_stylesheet do |stylesheet|
|
112
|
+
ss_line = " = stylesheet_link_tag '#{stylesheet_prefix}#{stylesheet.to.sub(/\.sass$/,'.css')}'"
|
113
|
+
if stylesheet.options[:media]
|
114
|
+
ss_line += ", :media => '#{stylesheet.options[:media]}'"
|
115
|
+
end
|
116
|
+
if stylesheet.options[:ie]
|
117
|
+
ss_line = " /[if IE]\n " + ss_line
|
118
|
+
end
|
119
|
+
html << ss_line + "\n"
|
120
|
+
end
|
121
|
+
html
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|