rembrandt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 773b3a1b6359c6291e68f57a1abb5009c873a907
4
+ data.tar.gz: f0dc44bcf14bb1b9be8d8f7e082f0854db6af855
5
+ SHA512:
6
+ metadata.gz: b07e5b40347b92d9b2b94c30ca752f3c195aca62a42d5677fa3fd6b1dc4a6cf272afddfa456efd8754a648dcad239062592ec04f812bb863d3989d7b707ab68a
7
+ data.tar.gz: 89ff4b050fd5818fd2c25a195de141d3211f192569baa68165982e864e393adac73a0da4e1f1bdc578183e0c2317ebcf6ac08a88e37c49bc3c33dc7c3461f5d2
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rembrandt.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :minitest do
5
+ watch(%r{^lib/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" }
6
+ watch(%r{^test/.+_test\.rb})
7
+ watch(%r{^test/test_helper\.rb}) { 'test' }
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jeff Casimir
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Rembrandt
2
+
3
+ A tool for generating syntax-highlighted code, powered by Pygments.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rembrandt'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rembrandt
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ module Rembrandt
2
+ module Engines
3
+ class Pygmentize
4
+ def highlight(input, language)
5
+ tmp_file = File.open("./tmp/colorize_temp", "w")
6
+ tmp_file.write(input)
7
+ tmp_file.close
8
+ `pygmentize -f html -l #{language} ./tmp/colorize_temp`
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require 'uri'
2
+
3
+ module Rembrandt
4
+ module Engines
5
+ class WebService
6
+ def highlight(input, language)
7
+ Net::HTTP.post_form(url, {'lang'=>language, 'code'=>input}).body
8
+ end
9
+
10
+ def url
11
+ @url ||= URI.parse('http://pygmentize.herokuapp.com/')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Rembrandt
2
+ module Formatters
3
+ class Table
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ require './lib/rembrandt/engines/pygmentize'
2
+
3
+ module Rembrandt
4
+ class Highlighter
5
+ attr_reader :engine
6
+
7
+ def initialize(input_engine = nil)
8
+ @engine = (input_engine || default_engine).new
9
+ end
10
+
11
+ def default_language
12
+ "ruby"
13
+ end
14
+
15
+ def default_engine
16
+ Engines::Pygmentize
17
+ end
18
+
19
+ def highlight(input, language = default_language)
20
+ engine.highlight(input, language)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Rembrandt
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rembrandt.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "rembrandt/version"
2
+
3
+ module Rembrandt
4
+ end
data/rembrandt.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rembrandt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rembrandt"
8
+ spec.version = Rembrandt::VERSION
9
+ spec.authors = ["Jeff Casimir"]
10
+ spec.email = ["jeff@casimircreative.com"]
11
+ spec.description = "A library for generating and storing syntax-highlighted code"
12
+ spec.summary = "Powered by the amazing Pygments Python library."
13
+ spec.homepage = "http://github.com/jcasimir/rembrandt"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest", "~> 5"
24
+ spec.add_development_dependency "guard-minitest"
25
+ spec.add_development_dependency "vcr"
26
+ spec.add_development_dependency "webmock"
27
+ end
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://pygmentize.herokuapp.com/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: lang=ruby&code=class+Sample%0A++def+a_method%0A++++puts+%22Some+String%22%0A++end%0Aend
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - '*/*'
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - pygmentize.herokuapp.com
18
+ Content-Type:
19
+ - application/x-www-form-urlencoded
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Content-Type:
26
+ - text/html; charset=utf-8
27
+ Date:
28
+ - Sun, 22 Dec 2013 06:55:17 GMT
29
+ Server:
30
+ - Werkzeug/0.8.1 Python/2.7.1
31
+ Content-Length:
32
+ - '300'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: |
38
+ <div class="highlight"><pre><span class="k">class</span> <span class="nc">Sample</span>
39
+ <span class="k">def</span> <span class="nf">a_method</span>
40
+ <span class="nb">puts</span> <span class="s2">&quot;Some String&quot;</span>
41
+ <span class="k">end</span>
42
+ <span class="k">end</span>
43
+ </pre></div>
44
+ http_version:
45
+ recorded_at: Sun, 22 Dec 2013 06:55:17 GMT
46
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,18 @@
1
+ require './test/test_helper'
2
+ require './lib/rembrandt/engines/pygmentize'
3
+
4
+ class EnginesPygmentizeTest < CodeHighlightTest
5
+ def test_it_exists
6
+ assert Rembrandt::Engines::Pygmentize.new
7
+ end
8
+
9
+ attr_reader :highlighter
10
+
11
+ def setup
12
+ @highlighter = Rembrandt::Engines::Pygmentize.new
13
+ end
14
+
15
+ def test_it_highlights
16
+ assert_highlight 'ruby_sample_1.rb', 'ruby'
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require './test/test_helper'
2
+ require './lib/rembrandt/engines/web_service'
3
+
4
+ class EnginesPygmentizeTest < CodeHighlightTest
5
+ def test_it_exists
6
+ assert Rembrandt::Engines::WebService.new
7
+ end
8
+
9
+ attr_reader :highlighter
10
+
11
+ def setup
12
+ @highlighter = Rembrandt::Engines::WebService.new
13
+ end
14
+
15
+ def test_it_highlights
16
+ VCR.use_cassette('web_engine_highlights_ruby_sample_1') do
17
+ assert_highlight 'ruby_sample_1.rb', 'ruby'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require './lib/rembrandt/formatters/table'
4
+
5
+ class FormattersTableTest < Minitest::Test
6
+ def test_it_exists
7
+ assert Rembrandt::Formatters::Table.new
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ require './test/test_helper'
2
+ require './lib/rembrandt/highlighter'
3
+
4
+ class HighlighterTest < CodeHighlightTest
5
+ def test_it_exists
6
+ assert Rembrandt::Highlighter
7
+ end
8
+
9
+ attr_reader :highlighter
10
+
11
+ def setup
12
+ @highlighter = Rembrandt::Highlighter.new
13
+ end
14
+
15
+ def test_it_has_a_highlight_method
16
+ assert highlighter.highlight("Hello, World")
17
+ end
18
+
19
+ def test_highlight_takes_an_input_and_a_language
20
+ assert highlighter.highlight("Hello, World", 'ruby')
21
+ end
22
+
23
+ def test_highlight_properly_highlights_ruby
24
+ assert_highlight 'ruby_sample_1.rb', 'ruby'
25
+ end
26
+
27
+ def test_highlight_properly_highlights_python
28
+ assert_highlight 'python_sample_1.py', 'python'
29
+ end
30
+
31
+ class StubEngine
32
+ def highlight(text, language)
33
+ "stub highlight"
34
+ end
35
+ end
36
+
37
+ def test_the_highlight_engine_is_configurable
38
+ stubbed_highlighter = Rembrandt::Highlighter.new(StubEngine)
39
+ assert_equal "stub highlight", stubbed_highlighter.highlight("hello", "ruby")
40
+ end
41
+ end
@@ -0,0 +1,2 @@
1
+ class HelloWorld:
2
+ print("Hello, World!")
@@ -0,0 +1,3 @@
1
+ <div class="highlight"><pre><span class="k">class</span> <span class="nc">HelloWorld</span><span class="p">:</span>
2
+ <span class="k">print</span><span class="p">(</span><span class="s">&quot;Hello, World!&quot;</span><span class="p">)</span>
3
+ </pre></div>
@@ -0,0 +1,5 @@
1
+ class Sample
2
+ def a_method
3
+ puts "Some String"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ <div class="highlight"><pre><span class="k">class</span> <span class="nc">Sample</span>
2
+ <span class="k">def</span> <span class="nf">a_method</span>
3
+ <span class="nb">puts</span> <span class="s2">&quot;Some String&quot;</span>
4
+ <span class="k">end</span>
5
+ <span class="k">end</span>
6
+ </pre></div>
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://pygmentize.herokuapp.com/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: lang=ruby&code=class+Sample%0A++def+a_method%0A++++puts+%22Some+String%22%0A++end%0Aend
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - '*/*'
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - pygmentize.herokuapp.com
18
+ Content-Type:
19
+ - application/x-www-form-urlencoded
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Content-Type:
26
+ - text/html; charset=utf-8
27
+ Date:
28
+ - Sun, 22 Dec 2013 06:56:30 GMT
29
+ Server:
30
+ - Werkzeug/0.8.1 Python/2.7.1
31
+ Content-Length:
32
+ - '300'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: |
38
+ <div class="highlight"><pre><span class="k">class</span> <span class="nc">Sample</span>
39
+ <span class="k">def</span> <span class="nf">a_method</span>
40
+ <span class="nb">puts</span> <span class="s2">&quot;Some String&quot;</span>
41
+ <span class="k">end</span>
42
+ <span class="k">end</span>
43
+ </pre></div>
44
+ http_version:
45
+ recorded_at: Sun, 22 Dec 2013 06:56:30 GMT
46
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,16 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'vcr'
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'test/support/vcr_cassettes'
7
+ c.hook_into :webmock
8
+ end
9
+
10
+ class CodeHighlightTest < Minitest::Test
11
+ def assert_highlight(filename, language)
12
+ input = File.read("./test/support/#{filename}")
13
+ expected = File.read("./test/support/#{filename}.html")
14
+ assert_equal expected, highlighter.highlight(input, language)
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rembrandt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Casimir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A library for generating and storing syntax-highlighted code
98
+ email:
99
+ - jeff@casimircreative.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - Guardfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - lib/rembrandt.rb
111
+ - lib/rembrandt/engines/pygmentize.rb
112
+ - lib/rembrandt/engines/web_service.rb
113
+ - lib/rembrandt/formatters/table.rb
114
+ - lib/rembrandt/highlighter.rb
115
+ - lib/rembrandt/version.rb
116
+ - rembrandt.gemspec
117
+ - support/vcr_cassettes/web_engine_highlights_ruby_sample_1.yml
118
+ - test/rembrandt/engines/pygmentize_test.rb
119
+ - test/rembrandt/engines/web_service_test.rb
120
+ - test/rembrandt/formatters/table_test.rb
121
+ - test/rembrandt/highlighter_test.rb
122
+ - test/support/python_sample_1.py
123
+ - test/support/python_sample_1.py.html
124
+ - test/support/ruby_sample_1.rb
125
+ - test/support/ruby_sample_1.rb.html
126
+ - test/support/vcr_cassettes/web_engine_highlights_ruby_sample_1.yml
127
+ - test/test_helper.rb
128
+ homepage: http://github.com/jcasimir/rembrandt
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.1.11
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Powered by the amazing Pygments Python library.
152
+ test_files:
153
+ - test/rembrandt/engines/pygmentize_test.rb
154
+ - test/rembrandt/engines/web_service_test.rb
155
+ - test/rembrandt/formatters/table_test.rb
156
+ - test/rembrandt/highlighter_test.rb
157
+ - test/support/python_sample_1.py
158
+ - test/support/python_sample_1.py.html
159
+ - test/support/ruby_sample_1.rb
160
+ - test/support/ruby_sample_1.rb.html
161
+ - test/support/vcr_cassettes/web_engine_highlights_ruby_sample_1.yml
162
+ - test/test_helper.rb