Module: Compass::Core::SassExtensions::Functions::Configuration
- Extended by:
- SassDeclarationHelper
- Included in:
- Sass::Script::Functions
- Defined in:
- lib/compass/core/sass_extensions/functions/configuration.rb
Constant Summary collapse
- OPTION_TRANSFORMER =
Hash.new() {|h, k| proc {|v, ctx| v.value } }
Instance Method Summary collapse
-
#absolute_path(relative_path) ⇒ Object
Returns an absolute path for the path relative to the sass file it was called from.
- #add_configuration(options) ⇒ Object
- #add_sass_configuration(project_path) ⇒ Object
-
#join_file_segments(*segments) ⇒ Object
Users who need to support windows and unix paths in their configuration should construct them with this helper function.
- #reset_configuration ⇒ Object
-
#split_filename(path) ⇒ Object
split a file into directory, basename, and extension.
-
#using_compass_compiler ⇒ Object
Returns true if the compass compiler is compiling this stylesheet.
Methods included from SassDeclarationHelper
Instance Method Details
#absolute_path(relative_path) ⇒ Object
Returns an absolute path for the path relative to the sass file it was called from.
13 14 15 |
# File 'lib/compass/core/sass_extensions/functions/configuration.rb', line 13 def absolute_path(relative_path) quoted_string(File.(File.join(File.dirname([:filename]), relative_path.value))) end |
#add_configuration(options) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/compass/core/sass_extensions/functions/configuration.rb', line 127 def add_configuration() attributes = {} .value.keys.each do |key| underscored = key.value.to_s.tr("-", "_") unless runtime_writable_attributes.find{|a| a.to_s == underscored} raise ArgumentError, "#{key} is not a valid configuration option." end underscored = underscored.to_sym attributes[underscored] = OPTION_TRANSFORMER[underscored].call(.value[key], self) end name = "#{.source_range.file}:#{.source_range.start_pos.line}" Compass.add_configuration(Compass::Configuration::Data.new(name, attributes)) null end |
#add_sass_configuration(project_path) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/compass/core/sass_extensions/functions/configuration.rb', line 40 def add_sass_configuration(project_path) css_location = template_location = nil if [:template_location] && [:template_location].is_a?(Array) css_location = File.([:template_location].first.last) template_location = File.([:template_location].first.first) else css_location = File.([:css_location]) if [:css_location] template_location = File.([:template_location]) if [:template_location] end original_filename = File.([:original_filename]) if [:original_filename] project_path = if project_path.value.nil? if css_location && template_location common_parent_directory(css_location, template_location) end else project_path.value end config = { :project_path => project_path, :cache => [:cache], :additional_import_paths => [:load_paths], :line_comments => [:line_comments] } unless [:quiet].nil? config.update(:disable_warnings => [:quiet]) end if project_path && css_location && (css_dir = relative_path_from(css_location, project_path)) config.update(:css_dir => css_dir) elsif css_location config.update(:css_path => css_location) end if project_path && template_location && (sass_dir = relative_path_from(template_location, project_path)) config.update(:sass_dir => sass_dir) elsif template_location config.update(:css_path => template_location) end config_name = "Sass Defaults: #{project_path ? relative_path_from(original_filename, project_path) : original_filename}" Compass.add_configuration(Compass::Configuration::Data.new(config_name, config)) null rescue => e puts e.backtrace.join("\n") raise end |
#join_file_segments(*segments) ⇒ Object
Users who need to support windows and unix paths in their configuration should construct them with this helper function.
7 8 9 |
# File 'lib/compass/core/sass_extensions/functions/configuration.rb', line 7 def join_file_segments(*segments) quoted_string(File.join(*segments.map{|s| assert_type s, :String; s.value})) end |
#reset_configuration ⇒ Object
34 35 36 37 |
# File 'lib/compass/core/sass_extensions/functions/configuration.rb', line 34 def reset_configuration() Compass.reset_configuration! null() end |
#split_filename(path) ⇒ Object
split a file into directory, basename, and extension
19 20 21 22 23 24 25 |
# File 'lib/compass/core/sass_extensions/functions/configuration.rb', line 19 def split_filename(path) pathname = Pathname.new(path.value) list(quoted_string(pathname.dirname.to_s), quoted_string(pathname.basename(pathname.extname).to_s), quoted_string(pathname.extname.to_s), :space) end |
#using_compass_compiler ⇒ Object
Returns true if the compass compiler is compiling this stylesheet.
29 30 31 |
# File 'lib/compass/core/sass_extensions/functions/configuration.rb', line 29 def using_compass_compiler bool([:compass] && [:compass][:compiler_in_use]) end |