Permalink
Browse files

Improve support for non-Rails environments

  • Loading branch information...
1 parent 7cd9caf commit 518a251a530ac9bd246889e790907bf4b585c7a5 @soffes soffes committed Jul 10, 2012
Showing with 16 additions and 7 deletions.
  1. +13 −5 lib/pizzazz.rb
  2. +1 −0 lib/pizzazz/colorer.rb
  3. +1 −1 lib/pizzazz/html.rb
  4. +1 −1 lib/pizzazz/version.rb
View
18 lib/pizzazz.rb
@@ -1,8 +1,3 @@
-require 'pizzazz/colorer'
-require 'pizzazz/html'
-require 'pizzazz/engine'
-require 'pizzazz/version'
-
module Pizzazz
TAB_SIZE = 2
@@ -11,3 +6,16 @@ def self.ify(object, options = nil)
p.ify
end
end
+
+# This is ugly. I'd love a better solution.
+begin
+ require 'rails'
+ require 'pizzazz/engine'
+ Pizzazz::RAILS_AVAILABLE = true
+rescue LoadError
+ Pizzazz::RAILS_AVAILABLE = false
+end
+
+require 'pizzazz/colorer'
+require 'pizzazz/html'
+require 'pizzazz/version'
View
1 lib/pizzazz/colorer.rb
@@ -11,6 +11,7 @@ def initialize(object, options = nil)
end
def ify
+ return '' unless @object
node(@object, @limit)
end
View
2 lib/pizzazz/html.rb
@@ -2,7 +2,7 @@ module Pizzazz
def self.ify_html(object, options = nil)
p = Colorer.new(object, options)
html = %Q{<pre class="pizzazz">#{p.ify}</pre>}
- html.html_safe if html.respond_to?(:html_safe)
+ html = html.html_safe if Pizzazz::RAILS_AVAILABLE
html
end
end
View
2 lib/pizzazz/version.rb
@@ -1,3 +1,3 @@
module Pizzazz
- VERSION = '0.1.1'
+ VERSION = '0.1.2'
end

0 comments on commit 518a251

Please sign in to comment.