Skip to content

Instantly share code, notes, and snippets.

@keiththomps
Last active August 29, 2015 14:02
Show Gist options
  • Save keiththomps/d4e0fce1ee9c822f6266 to your computer and use it in GitHub Desktop.
Save keiththomps/d4e0fce1ee9c822f6266 to your computer and use it in GitHub Desktop.
A way to use a style sheet for styles in an email.
sheet = ScssFile.new("sample.scss")
sheet.styles_for_class(".orange_header")
=> "color: #FF8E00; font-family: Arial, sans-serif; font-size: 24px;"
sheet.styles_for_class(".box_border_left")
=> "font-family: Arial, sans-serif; font-size: 16px; border-left: 1px solid #dddddd; padding: 10px;"
@mixin email-font {
font-family: Arial, sans-serif; font-size: 16px;
}
.orange_header {
color: #FF8E00;
font-family: Arial, sans-serif;
font-size: 24px;
}
.bottom_border {
border-bottom:1px solid #dddddd;
}
.box_border_left {
@include email-font;
border-left: 1px solid #dddddd;
padding:10px;
}
.box_border_right {
@include email-font;
border-right: 1px solid #dddddd;
padding:10px;
}
.table_header_row {
border-bottom:1px solid #dddddd;
font-family: Arial, sans-serif;
padding:10px;
}
.print_button {
background-color:#666666;
border-radius:4px;
color:#ffffff;
display:inline-block;
font-family:sans-serif;
font-size:13px;
font-weight:bold;
line-height:53px;
text-align:center;
text-decoration:none;
width:200px;
-webkit-text-size-adjust:none;
}
.policy_details_label {
font-size:12px;
line-height:20px;
text-align:justify;
}
require 'sass'
class ScssFile
attr_accessor :styles
def initialize(file_name)
@styles = Sass.compile_file(file_name).gsub("\n", "")
end
def styles_for_class(class_name)
rules[class_name] || ""
end
def rules
@_rules ||= styles.split("}").reduce({}) do |rules, line|
selector, properties = line.split("{").map(&:strip)
rules[selector] = properties
rules
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment