RuleSet should respect declaration order for Ruby Versions < 1.9
Closed this issue · 4 comments
The order in which rules are declared in a CSS file is important:
h1 {
margin: 0;
font-size: 24px;
}
h1 {
margin-bottom: 12px;
}
As written, the bottom margin for h1
elements is 12px
; but if the two declarations were switched, the bottom margin would be 0
.
Because the CssParser::RuleSet @declarations
attribute is a Hash, declaration order is ignored (for Ruby version < 1.9). This commit on this branch aims to fix this. RuleSet#each_declaration
now respects the declaration order.
Thanks Tyler. Much appreciated.
For some unknown reason, the body background style in http://premailer.dialect.ca/tests/styles.css has order => nil when run from the Premailer production server.
I'm unable to reproduce it locally, not matter how I try.
Added temporary workaround here: a3e5ae2 while I search for a proper solution.
From the error log:
NoMethodError - undefined method `<=>' for nil:NilClass:
premailer_app.rb:141:in `process_url'
premailer_app.rb:63:in `do_request'
premailer_app.rb:34:in `POST /'
/usr/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/methodoverride.rb:24:in `call'
/usr/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/commonlogger.rb:18:in `call'
/dh/passenger/lib/phusion_passenger/rack/request_handler.rb:92:in `process_request'
/dh/passenger/lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
/dh/passenger/lib/phusion_passenger/rack/application_spawner.rb:114:in `run'
/dh/passenger/lib/phusion_passenger/rack/application_spawner.rb:65:in `spawn_application'
/dh/passenger/lib/phusion_passenger/utils.rb:184:in `safe_fork'
/dh/passenger/lib/phusion_passenger/rack/application_spawner.rb:58:in `spawn_application'
/dh/passenger/lib/phusion_passenger/rack/application_spawner.rb:41:in `spawn_application'
/dh/passenger/lib/phusion_passenger/spawn_manager.rb:159:in `spawn_application'
/dh/passenger/lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:352:in `__send__'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
/dh/passenger/bin/passenger-spawn-server:61*** Exception NoMethodError in PhusionPassenger::Rack::ApplicationSpawner (undefined method `<=>' for nil:NilClass) (process 7535):
from /home/dialect/.gems/gems/css_parser-1.0.0/lib/css_parser/rule_set.rb:87:in `each_declaration'
from /home/dialect/.gems/gems/css_parser-1.0.0/lib/css_parser/rule_set.rb:87:in `sort'
from /home/dialect/.gems/gems/css_parser-1.0.0/lib/css_parser/rule_set.rb:87:in `each_declaration'
from /home/dialect/.gems/gems/css_parser-1.0.0/lib/css_parser/rule_set.rb:103:in `declarations_to_s'
from /home/dialect/.gems/gems/premailer-1.5.3/lib/premailer/premailer.rb:173:in `to_inline_css'
from /home/dialect/.gems/gems/premailer-1.5.3/lib/premailer/premailer.rb:160:in `each'
from /home/dialect/.gems/gems/premailer-1.5.3/lib/premailer/premailer.rb:160:in `to_inline_css'
from ./premailer_app.rb:141:in `process_url'
from ./premailer_app.rb:63:in `do_request'
from ./premailer_app.rb:34:in `POST /'
Just a thought, but is it possible that it's an issue with the premailer
library 1.5.3 vs. 1.5.4?
That's on the troubleshooting hit list, though I'd really like to know how it's even possible that rules are being parsed without an :order.