Skip to content
Browse files

* First real commit of InCurve gem

  • Loading branch information...
1 parent 63c8b3a commit 964ba2470757ddb82fa84ab2f807a40e2a24242e @stefanoverna stefanoverna committed Jul 30, 2010
Showing with 94 additions and 6 deletions.
  1. +1 −1 LICENSE
  2. +39 −3 README.rdoc
  3. +3 −2 Rakefile
  4. +22 −0 lib/incurve.rb
  5. +18 −0 lib/incurve/string_premailer.rb
  6. +11 −0 lib/incurve/view_helpers.rb
View
2 LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2009 Stefano Verna
+Copyright (c) 2010 weLaika
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
42 README.rdoc
@@ -1,7 +1,43 @@
-= incurve
+= InCurve
-Description goes here.
+InCurve provides a single, beautiful, handy helper method for your Rails app, letting you easily inline any CSS code present on your mail views.
+InCurve is just a small wrapper around the "premailer" gem.
+== Example
+
+If you have this mail view:
+
+ <% incurve_css do %>
+ <html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <style type="text/css">
+ body {
+ background-color: #e6e6e6;
+ background-position: top center;
+ background-repeat: no-repeat repeat-y;
+ margin: 0;
+ padding: 0;
+ }
+ </style>
+ </head>
+ <body>
+ </body>
+ </html>
+ <% end %>
+
+The mail you'll send will be like this:
+
+ <html>
+ <head>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
+ </head>
+ <body style="background-color: #e6e6e6; background-position: top center; background-repeat: no-repeat repeat-y; margin: 0; padding: 0;">
+ </body>
+ </html>
+
+Sweet.
+
== Note on Patches/Pull Requests
* Fork the project.
@@ -14,4 +50,4 @@ Description goes here.
== Copyright
-Copyright (c) 2010 Stefano Verna. See LICENSE for details.
+Copyright (c) 2010 weLaika. See LICENSE for details.
View
5 Rakefile
@@ -5,12 +5,13 @@ begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "incurve"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
+ gem.summary = %Q{Inline that damn CSS in your mail views.}
+ gem.description = %Q{incurve provides some handy helper methods for your Rails app, letting you easily inline your CSS code and auto-guess its text-only content.}
gem.email = "stefano.verna@welaika.com"
gem.homepage = "http://github.com/welaika/incurve"
gem.authors = ["Stefano Verna"]
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
+ gem.add_dependency("premailer")
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
View
22 lib/incurve.rb
@@ -0,0 +1,22 @@
+require 'active_support'
+require 'incurve/string_premailer'
+
+module InCurve
+
+ class << self
+ def enable
+ enable_actionpack
+ end
+
+ def enable_actionpack
+ return if ActionView::Base.instance_methods.include_method? :incurve_css
+ require 'incurve/view_helpers'
+ ActionView::Base.send :include, ViewHelpers
+ end
+ end
+
+end
+
+if defined? Rails
+ InCurve.enable_actionpack if defined? ActionController
+end
View
18 lib/incurve/string_premailer.rb
@@ -0,0 +1,18 @@
+require 'premailer'
+
+class StringPremailer < Premailer
+
+ protected
+
+ def load_html(path)
+ if path.is_a?(IO) || path.is_a?(StringIO)
+ @html_file = "http://foo.bar"
+ Hpricot(path.read)
+ elsif @is_local_file
+ Hpricot(File.open(path, "r") {|f| f.read })
+ else
+ Hpricot(open(path))
+ end
+ end
+
+end
View
11 lib/incurve/view_helpers.rb
@@ -0,0 +1,11 @@
+module InCurve
+ module ViewHelpers
+
+ def incurve_css(&block)
+ c = capture(&block)
+ premailer = StringPremailer.new(StringIO.new(c))
+ premailer.to_inline_css.html_safe
+ end
+
+ end
+end

0 comments on commit 964ba24

Please sign in to comment.
Something went wrong with that request. Please try again.