Module: Precssious

Defined in:
lib/precssious.rb,
lib/precssious/rule.rb,
lib/precssious/token.rb,
lib/precssious/value.rb,
lib/precssious/preprocessor.rb

Defined Under Namespace

Classes: Preprocessor, Rule, Token, Value

Class Method Summary collapse

Class Method Details

.directoryObject



11
# File 'lib/precssious.rb', line 11

def self.directory; @directory; end

.directory=(value) ⇒ Object



10
# File 'lib/precssious.rb', line 10

def self.directory=(value); @directory = value; end

.perform_preprocessing {|_self| ... } ⇒ Object

Generates CSS with names matching the directory names from all the CSS files included in that directory. By default searches public/stylesheets for directories to process (set Precssious.directory to change this).

Yields:

  • (_self)

Yield Parameters:

  • _self (Precssious)

    the object that the method was called on



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/precssious.rb', line 35

def self.perform_preprocessing
  yield self if block_given?
  @directory ||= Rails.root.join('public', 'stylesheets') if defined?(Rails)
  
  Dir["#{@directory}/*"].each do |dir|
    if File.directory?(dir)
      css = process_files(Dir["#{dir}/*.css"].sort, true)
      File.open "#{dir}/#{File.basename(dir)}.css", 'w' do |file|
        file.write css
      end
    end
  end
end

.process(input) ⇒ Object



50
51
52
# File 'lib/precssious.rb', line 50

def self.process(input)
  Preprocessor.new(input).rules.map { |x| x.to_s }.join "\n"
end

.process_files(files, zero = false) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/precssious.rb', line 54

def self.process_files(files, zero = false)
  result = zero ? [zero_css] : []
  files.each do |filename|
    File.open filename, 'r' do |file|
      result << '' << "/* #{File.basename(filename)} */"
      result << process(file.read)
    end
  end
  result.join "\n"
end

.start_rails_controller {|_self| ... } ⇒ Object

Loads the Precssious controller and adds routes to it. This route matches [directory]/:id/:filename.css, which by default is stylesheets/:id/:filename.css.

Yields:

  • (_self)

Yield Parameters:

  • _self (Precssious)

    the object that the method was called on



20
21
22
23
24
25
26
27
28
# File 'lib/precssious.rb', line 20

def self.start_rails_controller
  yield self if block_given?

  @directory ||= Rails.root.join('public', 'stylesheets')
  @web_path ||= 'stylesheets'

  require "precssious/rails/controller"
  ActionController::Routing::Routes.add_configuration_file(File.join(File.dirname(__FILE__), 'precssious', 'rails', 'routes.rb'))
end

.web_pathObject



13
# File 'lib/precssious.rb', line 13

def self.web_path; @web_path; end

.web_path=(value) ⇒ Object



12
# File 'lib/precssious.rb', line 12

def self.web_path=(value); @web_path = value; end

.zero_cssObject



65
66
67
# File 'lib/precssious.rb', line 65

def self.zero_css
  "html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym {border:0;font-variant:normal;}sup {vertical-align:text-top;}sub {vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}"  
end