Permalink
Browse files

Whitespace and formatting clean up

  • Loading branch information...
1 parent 04d7d09 commit 6a5a2e214048cc56c378cce340cf43490bec4ba7 @joshuaclayton committed Jul 2, 2010
View
@@ -3,24 +3,24 @@ module Blueprint
# path to the root Blueprint directory
ROOT_PATH = File.join(File.expand_path(File.dirname(__FILE__)), "../../")
# path to where the Blueprint CSS files are stored
- BLUEPRINT_ROOT_PATH = File.join(Blueprint::ROOT_PATH, 'blueprint')
+ BLUEPRINT_ROOT_PATH = File.join(Blueprint::ROOT_PATH, "blueprint")
# path to where the Blueprint CSS raw CSS files are stored
- SOURCE_PATH = File.join(Blueprint::BLUEPRINT_ROOT_PATH, 'src')
+ SOURCE_PATH = File.join(Blueprint::BLUEPRINT_ROOT_PATH, "src")
# path to where the Blueprint CSS generated test files are stored
- TEST_PATH = File.join(Blueprint::ROOT_PATH, 'tests')
+ TEST_PATH = File.join(Blueprint::ROOT_PATH, "tests")
# path to the root of the Blueprint scripts
- LIB_PATH = File.join(Blueprint::ROOT_PATH, 'lib', 'blueprint')
+ LIB_PATH = File.join(Blueprint::ROOT_PATH, "lib", "blueprint")
# path to where Blueprint plugins are stored
- PLUGINS_PATH = File.join(Blueprint::BLUEPRINT_ROOT_PATH, 'plugins')
+ PLUGINS_PATH = File.join(Blueprint::BLUEPRINT_ROOT_PATH, "plugins")
# settings YAML file where custom user settings are saved
- SETTINGS_FILE = File.join(Blueprint::ROOT_PATH, 'lib', 'settings.yml')
+ SETTINGS_FILE = File.join(Blueprint::ROOT_PATH, "lib", "settings.yml")
# path to validator jar file to validate generated CSS files
- VALIDATOR_FILE = File.join(Blueprint::LIB_PATH, 'validate', 'css-validator.jar')
+ VALIDATOR_FILE = File.join(Blueprint::LIB_PATH, "validate", "css-validator.jar")
# hash of compressed and source CSS files
CSS_FILES = {
- 'screen.css' => ['reset.css', 'typography.css', 'forms.css', 'grid.css'],
- 'print.css' => ['print.css'],
- 'ie.css' => ['ie.css']
+ "screen.css" => ["reset.css", "typography.css", "forms.css", "grid.css"],
+ "print.css" => ["print.css"],
+ "ie.css" => ["ie.css"]
}
# default number of columns for Blueprint layout
@@ -35,5 +35,5 @@ module Blueprint
end
Dir["#{File.join(Blueprint::LIB_PATH)}/*"].each do |file|
- require "#{file}" if file =~ /\.rb$/ && file !~ /blueprint.rb/
-end
+ require file if file =~ /\.rb$/ && file !~ /blueprint\.rb/
+end
View
@@ -1,27 +1,27 @@
-require 'yaml'
-require 'optparse'
+require "yaml"
+require "optparse"
module Blueprint
class Compressor
- TEST_FILES = ['index.html',
- 'parts/elements.html',
- 'parts/forms.html',
- 'parts/grid.html',
- 'parts/sample.html']
-
+ TEST_FILES = ["index.html",
+ "parts/elements.html",
+ "parts/forms.html",
+ "parts/grid.html",
+ "parts/sample.html"]
+
attr_accessor :namespace, :custom_css, :custom_layout, :semantic_classes, :project_name, :plugins
attr_reader :custom_path, :loaded_from_settings, :destination_path, :script_name
-
+
# overridden setter method for destination_path
# also sets custom_path flag on Blueprint::Compressor instance
def destination_path=(path)
@destination_path = path
@custom_path = @destination_path != Blueprint::BLUEPRINT_ROOT_PATH
end
-
+
# constructor
def initialize
# set up defaults
- @script_name = File.basename($0)
+ @script_name = File.basename($0)
@loaded_from_settings = false
@settings_file = Blueprint::SETTINGS_FILE
self.namespace = ""
@@ -31,11 +31,11 @@ def initialize
self.custom_css = {}
self.semantic_classes = {}
self.plugins = []
-
+
self.options.parse!(ARGV)
initialize_project_from_yaml(self.project_name)
end
-
+
# generates output CSS based on any args passed in
# overwrites any existing CSS, as well as grid.png and tests
def generate!
@@ -44,10 +44,10 @@ def generate!
generate_tests # updates HTML with custom namespaces in order to test the generated library. TODO: have tests kick out to custom location
output_footer # informs the user that the CSS generation process is complete
end
-
+
def options #:nodoc:#
OptionParser.new do |o|
- o.set_summary_indent(' ')
+ o.set_summary_indent(" ")
o.banner = "Usage: #{@script_name} [options]"
o.define_head "Blueprint Compressor"
o.separator ""
@@ -71,30 +71,39 @@ def options #:nodoc:#
end
end
- private
-
+ private
+
# attempts to load output settings from settings.yml
def initialize_project_from_yaml(project_name = nil)
# ensures project_name is set and settings.yml is present
return unless (project_name && File.exist?(@settings_file))
-
+
# loads yaml into hash
projects = YAML::load(File.path_to_string(@settings_file))
-
+
if (project = projects[project_name]) # checks to see if project info is present
- self.namespace = project['namespace'] || ""
- self.destination_path = (self.destination_path == Blueprint::BLUEPRINT_ROOT_PATH ? project['path'] : self.destination_path) || Blueprint::BLUEPRINT_ROOT_PATH
- self.custom_css = project['custom_css'] || {}
- self.semantic_classes = project['semantic_classes'] || {}
- self.plugins = project['plugins'] || []
-
- if (layout = project['custom_layout'])
- self.custom_layout = CustomLayout.new(:column_count => layout['column_count'], :column_width => layout['column_width'], :gutter_width => layout['gutter_width'], :input_padding => layout['input_padding'], :input_border => layout['input_border'])
+ self.destination_path = if self.destination_path == Blueprint::BLUEPRINT_ROOT_PATH
+ project["path"]
+ else
+ self.destination_path
+ end
+ self.destination_path ||= Blueprint::BLUEPRINT_ROOT_PATH
+ self.namespace = project["namespace"] || ""
+ self.custom_css = project["custom_css"] || {}
+ self.semantic_classes = project["semantic_classes"] || {}
+ self.plugins = project["plugins"] || []
+
+ if (layout = project["custom_layout"])
+ self.custom_layout = CustomLayout.new(:column_count => layout["column_count"],
+ :column_width => layout["column_width"],
+ :gutter_width => layout["gutter_width"],
+ :input_padding => layout["input_padding"],
+ :input_border => layout["input_border"])
end
@loaded_from_settings = true
end
end
-
+
def generate_css_files
Blueprint::CSS_FILES.each do |output_file_name, css_source_file_names|
css_output_path = File.join(destination_path, output_file_name)
@@ -103,41 +112,44 @@ def generate_css_files
# CSS file generation
css_output = css_file_header # header included on all three Blueprint-generated files
css_output += "\n\n"
-
+
# Iterate through src/ .css files and compile to individual core compressed file
css_source_file_names.each do |css_source_file|
puts " + src/#{css_source_file}"
css_output += "/* #{css_source_file} */\n" if css_source_file_names.any?
-
- source_options = if self.custom_layout && css_source_file == 'grid.css'
+
+ source_options = if self.custom_layout && css_source_file == "grid.css"
self.custom_layout.generate_grid_css
else
File.path_to_string File.join(Blueprint::SOURCE_PATH, css_source_file)
end
-
- css_output += Blueprint::CSSParser.new(source_options, :namespace => namespace).to_s
+
+ css_output += Blueprint::CSSParser.new(source_options,
+ :namespace => namespace).to_s
css_output += "\n"
end
-
+
#append CSS from plugins
css_output = append_plugin_css(css_output, output_file_name)
-
+
# append CSS from custom files
css_output = append_custom_css(css_output, output_file_name)
-
+
#save CSS to correct path, stripping out any extra whitespace at the end of the file
File.string_to_file(css_output.rstrip, css_output_path)
end
# append semantic class names if set
append_semantic_classes
-
+
#attempt to generate a grid.png file
- if (grid_builder = GridBuilder.new(:column_width => self.custom_layout.column_width, :gutter_width => self.custom_layout.gutter_width, :output_path => File.join(self.destination_path, 'src')))
+ if (grid_builder = GridBuilder.new(:column_width => self.custom_layout.column_width,
+ :gutter_width => self.custom_layout.gutter_width,
+ :output_path => File.join(self.destination_path, "src")))
grid_builder.generate!
end
end
-
+
def append_custom_css(css, current_file_name)
# check to see if a custom (non-default) location was used for output files
# if custom path is used, handle custom CSS, if any
@@ -146,67 +158,80 @@ def append_custom_css(css, current_file_name)
self.custom_css[current_file_name].each do |custom_css|
overwrite_base = custom_css || "my-#{current_file_name}"
overwrite_path = File.join(destination_path, overwrite_base)
- overwrite_css = File.exists?(overwrite_path) ? File.path_to_string(overwrite_path) : ""
-
+ overwrite_css = if File.exists?(overwrite_path)
+ File.path_to_string(overwrite_path)
+ else
+ ""
+ end
+
# if there's CSS present, add it to the CSS output
unless overwrite_css.blank?
puts " + custom styles (#{custom_css})\n"
css += "/* #{overwrite_base} */\n"
css += CSSParser.new(overwrite_css).to_s + "\n"
end
end
-
+
css
end
def append_plugin_css(css, current_file_name)
return css unless self.plugins.any?
-
+
plugin_css = ""
-
+
self.plugins.each do |plugin|
plugin_file_specific = File.join(Blueprint::PLUGINS_PATH, plugin, current_file_name)
plugin_file_generic = File.join(Blueprint::PLUGINS_PATH, plugin, "#{plugin}.css")
-
+
file = if File.exists?(plugin_file_specific)
plugin_file_specific
elsif File.exists?(plugin_file_generic) && current_file_name =~ /^screen|print/
plugin_file_generic
end
-
+
if file
puts " + #{plugin} plugin\n"
plugin_css += "/* #{plugin} */\n"
plugin_css += CSSParser.new(File.path_to_string(file)).to_s + "\n"
Dir.glob(File.join(File.dirname(file), "**", "**")).each do |cp|
- short_path = cp.gsub(/#{File.dirname(file)}./ , '')
+ short_path = cp.gsub(/#{File.dirname(file)}./ , "")
# make directory if it doesn't exist
directory = File.dirname(short_path)
- FileUtils.mkdir_p(File.join(destination_path, directory)) unless directory == "."
- FileUtils.cp cp, File.join(destination_path, short_path) unless File.directory?(File.join(File.dirname(file), short_path)) || cp == file
+ if directory != "."
+ FileUtils.mkdir_p(File.join(destination_path, directory))
+ end
+
+ unless File.directory?(File.join(File.dirname(file), short_path)) || cp == file
+ FileUtils.cp(cp, File.join(destination_path, short_path))
+ end
end
end
end
-
+
css += plugin_css
end
-
+
def append_semantic_classes
screen_output_path = File.join(self.destination_path, "screen.css")
- semantic_styles = SemanticClassNames.new(:namespace => self.namespace, :source_file => screen_output_path).css_from_assignments(self.semantic_classes)
+ semantic_classes = SemanticClassNames.new(:namespace => self.namespace,
+ :source_file => screen_output_path)
+ semantic_styles = semantic_classes.css_from_assignments(self.semantic_classes)
return if semantic_styles.blank?
css = File.path_to_string(screen_output_path)
css += "\n\n/* semantic class names */\n"
css += semantic_styles
File.string_to_file(css.rstrip, screen_output_path)
end
-
+
def generate_tests
puts "\n Updating namespace to \"#{namespace}\" in test files:"
- test_files = Compressor::TEST_FILES.map {|f| File.join(Blueprint::TEST_PATH, *f.split(/\//))}
-
+ test_files = Compressor::TEST_FILES.map do |file|
+ File.join(Blueprint::TEST_PATH, *file.split(/\//))
+ end
+
test_files.each do |file|
puts " + #{file}"
Namespace.new(file, namespace)
@@ -242,7 +267,7 @@ def output_footer
puts " **"
puts " #{"*" * 100}\n\n"
end
-
+
def css_file_header
%(/* -----------------------------------------------------------------------
@@ -257,7 +282,7 @@ def css_file_header
----------------------------------------------------------------------- */)
end
-
+
def putsv(str)
puts str if $verbose
end
View
@@ -1,20 +1,20 @@
class String
# see if string has any content
def blank?; self.length.zero?; end
-
+
# strip space after :, remove newlines, replace multiple spaces with only one space, remove comments
def strip_space!
- replace self.gsub(/:\s*/, ':').gsub(/\n/, '').gsub(/\s+/, ' ').gsub(/(\/\*).*?(\*\/)/, '')
+ replace self.gsub(/:\s*/, ":").gsub(/\n/, "").gsub(/\s+/, " ").gsub(/(\/\*).*?(\*\/)/, "")
end
-
+
# remove newlines, insert space after comma, replace two spaces with one space after comma
def strip_selector_space!
- replace self.gsub(/(\n)/, '').gsub(',', ', ').gsub(', ', ', ')
+ replace self.gsub(/\n/, "").gsub(",", ", ").gsub(", ", ", ")
end
-
+
# remove leading whitespace, remove end whitespace
def strip_side_space!
- replace self.gsub(/^\s+/, '').gsub(/\s+$/, $/)
+ replace self.gsub(/^\s+/, "").gsub(/\s+$/, $/)
end
end
@@ -29,11 +29,11 @@ class File
def self.path_to_string(path)
File.new(path).read
end
-
+
# saves a string to a specified file path
def self.string_to_file(string, path)
directory = File.dirname(path)
FileUtils.mkdir_p directory unless File.directory?(directory)
- File.open(path, 'w') { |f| f << string }
+ File.open(path, "w") { |f| f << string }
end
-end
+end
Oops, something went wrong.

0 comments on commit 6a5a2e2

Please sign in to comment.