Skip to content

Commit

Permalink
* First real commit of InCurve gem
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Verna committed Jul 30, 2010
1 parent 63c8b3a commit 964ba24
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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
Expand Down
42 changes: 39 additions & 3 deletions 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.
Expand All @@ -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.
5 changes: 3 additions & 2 deletions Rakefile
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions 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
18 changes: 18 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions 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.