albeano 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.md +28 -0
- data/lib/albeano.rb +39 -0
- data/spec/albeano_spec.rb +61 -0
- metadata +97 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2010 Lee Jarvis
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Albeano
|
|
2
|
+
=======
|
|
3
|
+
|
|
4
|
+
Installation
|
|
5
|
+
------------
|
|
6
|
+
|
|
7
|
+
You need to ensure you have [Pygments](http://pygments.org/) syntax highlighter
|
|
8
|
+
installed on your system and your application has access to the `pygmentize`
|
|
9
|
+
executable. Then it's as easy as:
|
|
10
|
+
|
|
11
|
+
gem install albeano
|
|
12
|
+
|
|
13
|
+
Usage
|
|
14
|
+
-----
|
|
15
|
+
|
|
16
|
+
Albeano takes your orginal text and strips out the `[code]` style snippets
|
|
17
|
+
producing a nicely formatted document with HTML syntax highlighted code inserts.
|
|
18
|
+
Perfect for embedding code into blog posts.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Albeano.generate(text)
|
|
22
|
+
Albeano.generate(File.new(path_to_file))
|
|
23
|
+
|
|
24
|
+
You can even have it return markdown. Just make sure you have
|
|
25
|
+
[RDiscount](https://github.com/rtomayko/rdiscount) installed
|
|
26
|
+
|
|
27
|
+
Albeano.new(text).to_markdown
|
|
28
|
+
Albeano.new(text).to_markdown(:smart, :filter_html)
|
data/lib/albeano.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'albino'
|
|
2
|
+
|
|
3
|
+
class Albeano
|
|
4
|
+
VERSION = '1.0.0'
|
|
5
|
+
|
|
6
|
+
def self.generate(text)
|
|
7
|
+
new(text).generate
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def initialize(text)
|
|
11
|
+
if text.respond_to?(:read)
|
|
12
|
+
@text = text.read
|
|
13
|
+
else
|
|
14
|
+
@text = text
|
|
15
|
+
end
|
|
16
|
+
@markdown = nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def generate
|
|
20
|
+
@text.gsub(/\[code(?:=(.+?))?\]\s*(.+?)\s*\[\/code\]/m) do
|
|
21
|
+
Albino.colorize($2, $1 || :text)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
alias :to_s :generate
|
|
26
|
+
|
|
27
|
+
def to_markdown(*extensions)
|
|
28
|
+
begin
|
|
29
|
+
require 'rdiscount'
|
|
30
|
+
rescue LoadError
|
|
31
|
+
raise "Albeano requires RDiscount to render markdown"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
@markdown ||= RDiscount.new(generate).to_html
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
alias :to_md :to_markdown
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require File.expand_path('../../lib/albeano', __FILE__)
|
|
2
|
+
require 'tempfile'
|
|
3
|
+
|
|
4
|
+
describe Albeano do
|
|
5
|
+
|
|
6
|
+
describe "::generate #to_s/#generate" do
|
|
7
|
+
it "converts [code] blocks into syntax highlighted snippets" do
|
|
8
|
+
Albeano.generate("[code]foo bar[/code]").should == Albino.colorize("foo bar")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "trims left/right whitespace from inside [code] tags" do
|
|
12
|
+
Albeano.generate("[code]\n\n foo\nbar\n [/code]").should == Albino.colorize("foo\nbar")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "highlights language specific code" do
|
|
16
|
+
ruby = "[code=ruby]print 'foo bar'[/code]"
|
|
17
|
+
perl = "[code=perl]print 'foo bar'[/code]"
|
|
18
|
+
python = "[code=python]print 'foo bar'[/code]"
|
|
19
|
+
|
|
20
|
+
Albeano.generate(ruby).should == Albino.colorize("print 'foo bar'", :ruby)
|
|
21
|
+
Albeano.generate(perl).should == Albino.colorize("print 'foo bar'", :perl)
|
|
22
|
+
Albeano.generate(python).should == Albino.colorize("print 'foo bar'", :python)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "highlights multiple code blocks" do
|
|
26
|
+
text = "[code=ruby]print 'foo bar'[/code]"
|
|
27
|
+
text << "[code=perl]print 'foo bar'[/code]"
|
|
28
|
+
|
|
29
|
+
Albeano.generate(text).should ==
|
|
30
|
+
Albino.colorize("print 'foo bar'", :ruby) + Albino.colorize("print 'foo bar'", :perl)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "excepts a file or string" do
|
|
34
|
+
Tempfile.open("albeano") do |tmp|
|
|
35
|
+
tmp << Albeano.generate("[code]foo bar[/code]")
|
|
36
|
+
tmp.flush
|
|
37
|
+
Albeano.generate(File.new(tmp.path)).should == Albino.colorize("foo bar")
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "ignores text outside [code] tags" do
|
|
42
|
+
text = "lorem ipsum\n\n"
|
|
43
|
+
text << "[code=ruby]print 'foo bar'[/code]"
|
|
44
|
+
text << "dolor sit amet"
|
|
45
|
+
|
|
46
|
+
Albeano.generate(text).should ==
|
|
47
|
+
"lorem ipsum\n\n" + Albino.colorize("print 'foo bar'", :ruby) + "dolor sit amet"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "does not highlight snippets with no closing code tag" do
|
|
51
|
+
Albeano.generate("[code]print 'foo bar'").should_not == Albino.colorize("print 'foo bar'")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "to_markdown" do
|
|
56
|
+
it "should return markdown formatted text" do
|
|
57
|
+
Albeano.new("**foo bar**").to_md.should == "<p><strong>foo bar</strong></p>\n"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: albeano
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 1
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
version: 1.0.0
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Lee Jarvis
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-11-26 00:00:00 +00:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: albino
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
none: false
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
segments:
|
|
29
|
+
- 1
|
|
30
|
+
- 0
|
|
31
|
+
version: "1.0"
|
|
32
|
+
type: :runtime
|
|
33
|
+
version_requirements: *id001
|
|
34
|
+
- !ruby/object:Gem::Dependency
|
|
35
|
+
name: rspec
|
|
36
|
+
prerelease: false
|
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
38
|
+
none: false
|
|
39
|
+
requirements:
|
|
40
|
+
- - "="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
segments:
|
|
43
|
+
- 2
|
|
44
|
+
- 1
|
|
45
|
+
- 0
|
|
46
|
+
version: 2.1.0
|
|
47
|
+
type: :development
|
|
48
|
+
version_requirements: *id002
|
|
49
|
+
description: Albeano lets you to write language specifics code snippets within text and returns Pygments generated HTML syntax highlighted code
|
|
50
|
+
email: lee@jarvis.co
|
|
51
|
+
executables: []
|
|
52
|
+
|
|
53
|
+
extensions: []
|
|
54
|
+
|
|
55
|
+
extra_rdoc_files: []
|
|
56
|
+
|
|
57
|
+
files:
|
|
58
|
+
- LICENSE
|
|
59
|
+
- README.md
|
|
60
|
+
- lib/albeano.rb
|
|
61
|
+
- spec/albeano_spec.rb
|
|
62
|
+
has_rdoc: true
|
|
63
|
+
homepage:
|
|
64
|
+
licenses: []
|
|
65
|
+
|
|
66
|
+
post_install_message:
|
|
67
|
+
rdoc_options: []
|
|
68
|
+
|
|
69
|
+
require_paths:
|
|
70
|
+
- lib
|
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
|
+
none: false
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
segments:
|
|
77
|
+
- 1
|
|
78
|
+
- 8
|
|
79
|
+
- 6
|
|
80
|
+
version: 1.8.6
|
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
|
+
none: false
|
|
83
|
+
requirements:
|
|
84
|
+
- - ">="
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
segments:
|
|
87
|
+
- 0
|
|
88
|
+
version: "0"
|
|
89
|
+
requirements: []
|
|
90
|
+
|
|
91
|
+
rubyforge_project:
|
|
92
|
+
rubygems_version: 1.3.7
|
|
93
|
+
signing_key:
|
|
94
|
+
specification_version: 3
|
|
95
|
+
summary: BBCode style wrapper for Pygments
|
|
96
|
+
test_files: []
|
|
97
|
+
|