almost-happy 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/almost-happy.gemspec CHANGED
@@ -5,44 +5,42 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{almost-happy}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Darcy Laycock"]
12
- s.date = %q{2010-07-18}
12
+ s.date = %q{2010-12-11}
13
13
  s.description = %q{Helpers, convertors etc for Rails 3 to make page / post models for simple cases simple}
14
14
  s.email = %q{sutto@sutto.net}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.md"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.md",
24
- "Rakefile",
25
- "almost-happy.gemspec",
26
- "lib/almost-happy.rb",
27
- "lib/almost_happy.rb",
28
- "lib/almost_happy/active_record_mixin.rb",
29
- "lib/almost_happy/convertable.rb",
30
- "lib/almost_happy/convertor.rb",
31
- "lib/almost_happy/format_validator.rb",
32
- "lib/almost_happy/publishable.rb",
33
- "lib/almost_happy/scopeable.rb",
34
- "lib/vendor/albino.rb",
35
- "test/helper.rb",
36
- "test/test_almost-happy.rb"
21
+ "LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "almost-happy.gemspec",
25
+ "lib/almost-happy.rb",
26
+ "lib/almost_happy.rb",
27
+ "lib/almost_happy/active_record_mixin.rb",
28
+ "lib/almost_happy/convertable.rb",
29
+ "lib/almost_happy/convertor.rb",
30
+ "lib/almost_happy/format_validator.rb",
31
+ "lib/almost_happy/publishable.rb",
32
+ "lib/almost_happy/scopeable.rb",
33
+ "lib/vendor/albino.rb",
34
+ "test/helper.rb",
35
+ "test/test_almost-happy.rb"
37
36
  ]
38
37
  s.homepage = %q{http://github.com/Sutto/almost-happy}
39
- s.rdoc_options = ["--charset=UTF-8"]
40
38
  s.require_paths = ["lib"]
41
39
  s.rubygems_version = %q{1.3.7}
42
40
  s.summary = %q{Simple tools for AR + Rails 3 to help make managing your content easy}
43
41
  s.test_files = [
44
42
  "test/helper.rb",
45
- "test/test_almost-happy.rb"
43
+ "test/test_almost-happy.rb"
46
44
  ]
47
45
 
48
46
  if s.respond_to? :specification_version then
data/lib/almost_happy.rb CHANGED
@@ -4,7 +4,7 @@ require 'active_support/core_ext/class/attribute'
4
4
  require 'active_support/concern'
5
5
 
6
6
  module AlmostHappy
7
- VERSION = '0.3.0'.freeze
7
+ VERSION = '0.4.0'.freeze
8
8
 
9
9
  extend ActiveSupport::Autoload
10
10
 
@@ -7,6 +7,10 @@ require File.expand_path('../vendor/albino', File.dirname(__FILE__))
7
7
  module AlmostHappy
8
8
  class Convertor
9
9
 
10
+ def self.use_web_api!
11
+ Albino.use_web_api = true
12
+ end
13
+
10
14
  class Renderer < Struct.new(:name, :options, :renderer)
11
15
 
12
16
  def [](key)
data/lib/vendor/albino.rb CHANGED
@@ -42,9 +42,16 @@
42
42
  # GitHub // http://github.com
43
43
  #
44
44
  require 'open4'
45
+ require 'net/http'
46
+ require 'uri'
47
+ require 'tempfile'
45
48
 
46
49
  class Albino
47
- @@bin = Rails.env.development? ? 'pygmentize' : '/usr/bin/pygmentize'
50
+ @@bin = (defined?(Rails.env) && Rails.env.development?) ? 'pygmentize' : '/usr/bin/pygmentize'
51
+
52
+ @@use_web_api = false
53
+
54
+ WEB_API_ROOT = URI.parse('http://pygments.appspot.com/')
48
55
 
49
56
  def self.highlight_code(html)
50
57
  doc = Nokogiri::HTML(html)
@@ -65,6 +72,14 @@ class Albino
65
72
  def self.bin=(path)
66
73
  @@bin = path
67
74
  end
75
+
76
+ def self.use_web_api?
77
+ @@use_web_api
78
+ end
79
+
80
+ def self.use_web_api=(value)
81
+ @@use_web_api = !!value
82
+ end
68
83
 
69
84
  def self.colorize(*args)
70
85
  new(*args).colorize
@@ -73,6 +88,7 @@ class Albino
73
88
  def initialize(target, lexer = :text, format = :html)
74
89
  @target = File.exists?(target) ? File.read(target) : target rescue target
75
90
  @options = { :l => lexer, :f => format }
91
+ @web_options = {'lang' => lexer.to_s}
76
92
  end
77
93
 
78
94
  def execute(command)
@@ -84,9 +100,18 @@ class Albino
84
100
  ensure
85
101
  tmp.unlink if tmp
86
102
  end
103
+
104
+ def highlight_via_api
105
+ request = Net::HTTP.post_form(WEB_API_ROOT, @web_options.merge('code' => @target))
106
+ request.body
107
+ end
87
108
 
88
109
  def colorize(options = {})
89
- execute @@bin + convert_options(options)
110
+ if self.class.use_web_api?
111
+ highlight_via_api
112
+ else
113
+ execute @@bin + convert_options(options)
114
+ end
90
115
  end
91
116
  alias_method :to_s, :colorize
92
117
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: almost-happy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Darcy Laycock
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-18 00:00:00 +08:00
18
+ date: 2010-12-11 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -116,7 +116,6 @@ extra_rdoc_files:
116
116
  - README.md
117
117
  files:
118
118
  - .document
119
- - .gitignore
120
119
  - LICENSE
121
120
  - README.md
122
121
  - Rakefile
@@ -137,8 +136,8 @@ homepage: http://github.com/Sutto/almost-happy
137
136
  licenses: []
138
137
 
139
138
  post_install_message:
140
- rdoc_options:
141
- - --charset=UTF-8
139
+ rdoc_options: []
140
+
142
141
  require_paths:
143
142
  - lib
144
143
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC