literate-ruby 0.0.1
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.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +19 -0
- data/README.md +78 -0
- data/Rakefile +7 -0
- data/bin/literate-ruby +5 -0
- data/lib/literate-ruby.rb +86 -0
- data/lib/literate-ruby/version.rb +3 -0
- data/literate-ruby.gemspec +23 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af3d9f0e4094cc30bd9c2c5ce55f0c7dca4677ae
|
4
|
+
data.tar.gz: 460a0c484c3506d001ffcf292dd3b1eea7b61605
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66d594969d6def6b9ed58883f8dd6bc3bc426b2c5fb7c05845819fe976ee1702faac2a58cbd07f5cc801e127c79ae0798a6a0ba85bf5f5993bdfddb1bf4daf10
|
7
|
+
data.tar.gz: be34836dfc728e3fc37331ef0c865988302d54f098d1d077f3129d9f514e6c82bcb144c564ecf48d678126ac7c80b12c23aa0632e47500312fb6db4e3c4b06f6
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
literate-ruby (0.0.1)
|
5
|
+
kramdown (~> 1.2.0)
|
6
|
+
pygments.rb (~> 0.5.4)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
kramdown (1.2.0)
|
13
|
+
posix-spawn (0.3.6)
|
14
|
+
pygments.rb (0.5.4)
|
15
|
+
posix-spawn (~> 0.3.6)
|
16
|
+
yajl-ruby (~> 1.1.0)
|
17
|
+
rake (10.1.0)
|
18
|
+
rspec (2.14.1)
|
19
|
+
rspec-core (~> 2.14.0)
|
20
|
+
rspec-expectations (~> 2.14.0)
|
21
|
+
rspec-mocks (~> 2.14.0)
|
22
|
+
rspec-core (2.14.7)
|
23
|
+
rspec-expectations (2.14.4)
|
24
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
25
|
+
rspec-mocks (2.14.4)
|
26
|
+
yajl-ruby (1.1.0)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
literate-ruby!
|
33
|
+
rake
|
34
|
+
rspec (~> 2.14.1)
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Stewart
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Literate Ruby
|
2
|
+
|
3
|
+
A simple Ruby script that lets you enjoy literate programming in Ruby a little
|
4
|
+
bit more.
|
5
|
+
|
6
|
+
## How do I use it?
|
7
|
+
|
8
|
+
Given a `.litrb` file like the following (let's call it `example.litrb`):
|
9
|
+
|
10
|
+
# Literate Programming Is Fun
|
11
|
+
|
12
|
+
Literate programming is a great way to document your code, making it easily
|
13
|
+
accessible and well-explained to the reader. For example, below we define
|
14
|
+
a function that prints "Hello World", then run it.
|
15
|
+
|
16
|
+
def hello
|
17
|
+
puts "Hello, World!"
|
18
|
+
end
|
19
|
+
|
20
|
+
If the `literate-ruby.rb` script is run on this file, it will generate two
|
21
|
+
files:
|
22
|
+
|
23
|
+
- `example.rb` will contain all the code from the `.litrb` file, waiting to be
|
24
|
+
run by Ruby:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# example.rb
|
28
|
+
|
29
|
+
def hello
|
30
|
+
puts "Hello, World!"
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
- `example.html` will contain the converted markdown from the file, with
|
35
|
+
syntax-highlighted Ruby:
|
36
|
+
|
37
|
+
```html
|
38
|
+
<!-- example.html -->
|
39
|
+
<h1>Literate Programming Is Fun</h1>
|
40
|
+
|
41
|
+
<p>Literate programming is a great way to document your code, making it easily
|
42
|
+
accessible and well-explained to the reader. For example, below we define
|
43
|
+
a function that prints "Hello World", then run it.</p>
|
44
|
+
|
45
|
+
<div class="highlight"><pre><span class="k">def</span> <span class="nf">hello</span>
|
46
|
+
<span class="nb">puts</span> <span class="s2">"Hello, World!"</span>
|
47
|
+
<span class="k">end</span>
|
48
|
+
</pre></div>
|
49
|
+
```
|
50
|
+
|
51
|
+
## Dependencies:
|
52
|
+
|
53
|
+
Literate Ruby makes use of the following gems:
|
54
|
+
|
55
|
+
- [rdicount][]
|
56
|
+
- [pygments.rb][]
|
57
|
+
|
58
|
+
To install RDiscount, you'll need at least a basic build system, since it's
|
59
|
+
implemented in C.
|
60
|
+
|
61
|
+
If you have a Pygments install (`which pygmentize`), Pygments.rb will use that.
|
62
|
+
If not, it will need to use an external web service to perform syntax
|
63
|
+
highlighting.
|
64
|
+
|
65
|
+
[rdicount]: https://github.com/davidfstr/rdiscount/
|
66
|
+
[pygments.rb]: https://github.com/tmm1/pygments.rb
|
67
|
+
|
68
|
+
## TODO:
|
69
|
+
|
70
|
+
- support for directly running `.litrb` files
|
71
|
+
- support for processing a dir of `.litrb` fils
|
72
|
+
- support for reading Literate Ruby from stdin and outputting html or ruby to
|
73
|
+
stdout
|
74
|
+
- gemify or otherwise turn into a binary
|
75
|
+
|
76
|
+
## License
|
77
|
+
|
78
|
+
MIT. Plain and simple. See `LICENSE` for more details.
|
data/Rakefile
ADDED
data/bin/literate-ruby
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'pygments'
|
2
|
+
require 'kramdown'
|
3
|
+
|
4
|
+
module LiterateRuby
|
5
|
+
class << self
|
6
|
+
attr_reader :input, :ruby, :html, :basename
|
7
|
+
|
8
|
+
INDENTED_CODE_REGEX = / # Match a MARKDOWN CODE section.
|
9
|
+
(\r?\n) # $1: CODE must be preceded by blank line
|
10
|
+
( # $2: CODE contents
|
11
|
+
(?: # Group for multiple lines of code.
|
12
|
+
(?:\r?\n)+ # Each line preceded by a newline,
|
13
|
+
(?:[ ]{4}|\t).* # and begins with four spaces or tab.
|
14
|
+
)+ # One or more CODE lines
|
15
|
+
\r?\n # CODE folowed by blank line.
|
16
|
+
) # End $2: CODE contents
|
17
|
+
(?=\r?\n)? # CODE folowed by blank line.
|
18
|
+
/x
|
19
|
+
|
20
|
+
def print_help
|
21
|
+
warn " Usage:"
|
22
|
+
warn " literate-ruby [FILE].litrb"
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
|
26
|
+
def check_args
|
27
|
+
print_help if ARGV.length == 0
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_input
|
31
|
+
file = ARGV[0]
|
32
|
+
|
33
|
+
if File.exists?(file)
|
34
|
+
@input = File.read file
|
35
|
+
@basename = File.basename file, '.litrb'
|
36
|
+
else
|
37
|
+
print_help
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def extract_ruby
|
42
|
+
@ruby = @input.scan(INDENTED_CODE_REGEX).join('')
|
43
|
+
@ruby.gsub!(/^[ ]{4}/ , '')
|
44
|
+
@ruby.lstrip!.strip!
|
45
|
+
end
|
46
|
+
|
47
|
+
def syntax_highlight_ruby_blocks
|
48
|
+
@input.gsub! INDENTED_CODE_REGEX do |code|
|
49
|
+
code.gsub!(/^[ ]{4}/ , '')
|
50
|
+
code.strip!.lstrip!
|
51
|
+
|
52
|
+
highlighted_code = highlight_code code
|
53
|
+
"\n\n#{highlighted_code}\n"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def highlight_code(code)
|
58
|
+
Pygments.highlight code, :lexer => 'ruby'
|
59
|
+
end
|
60
|
+
|
61
|
+
def convert_markdown
|
62
|
+
syntax_highlight_ruby_blocks
|
63
|
+
markdown = Kramdown::Document.new @input
|
64
|
+
@html = markdown.to_html
|
65
|
+
end
|
66
|
+
|
67
|
+
def export_html
|
68
|
+
html_filename = File.expand_path("./#{@basename}.html")
|
69
|
+
File.write html_filename, @html
|
70
|
+
end
|
71
|
+
|
72
|
+
def export_ruby
|
73
|
+
ruby_filename = File.expand_path("./#{@basename}.rb")
|
74
|
+
File.write ruby_filename, @ruby
|
75
|
+
end
|
76
|
+
|
77
|
+
def start!
|
78
|
+
check_args
|
79
|
+
get_input
|
80
|
+
extract_ruby
|
81
|
+
convert_markdown
|
82
|
+
export_html
|
83
|
+
export_ruby
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path '../lib/literate-ruby/version', __FILE__
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "literate-ruby"
|
6
|
+
spec.version = LiterateRuby::VERSION
|
7
|
+
spec.authors = ["Andrew Stewart"]
|
8
|
+
spec.email = ["andrew@stwrt.ca"]
|
9
|
+
spec.description = %q{Literate Programming, with Ruby.}
|
10
|
+
spec.summary = %q{Literate Programming, with Ruby.}
|
11
|
+
spec.homepage = "https://github.com/stewart/literate-ruby"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "kramdown", "~> 1.2.0"
|
20
|
+
spec.add_dependency "pygments.rb", "~> 0.5.4"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: literate-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Stewart
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: kramdown
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pygments.rb
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.5.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.14.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.14.1
|
69
|
+
description: Literate Programming, with Ruby.
|
70
|
+
email:
|
71
|
+
- andrew@stwrt.ca
|
72
|
+
executables:
|
73
|
+
- literate-ruby
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/literate-ruby
|
83
|
+
- lib/literate-ruby.rb
|
84
|
+
- lib/literate-ruby/version.rb
|
85
|
+
- literate-ruby.gemspec
|
86
|
+
homepage: https://github.com/stewart/literate-ruby
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.0.3
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Literate Programming, with Ruby.
|
110
|
+
test_files: []
|