render-as-markdown 0.0.4 → 0.0.5
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 +8 -8
- data/HISTORY.md +12 -2
- data/README.md +73 -7
- data/TODO.md +3 -4
- data/lib/render-as-markdown/image.rb +18 -0
- data/lib/render-as-markdown/link.rb +21 -0
- data/lib/render-as-markdown/markdown-code.rb +21 -0
- data/lib/render-as-markdown/markdown-list.rb +32 -0
- data/lib/render-as-markdown/version.rb +1 -1
- data/lib/render-as-markdown.rb +6 -2
- data/test/code_test.rb +21 -0
- data/test/image_test.rb +20 -0
- data/test/link_test.rb +22 -0
- data/test/list_test.rb +17 -0
- metadata +14 -3
- data/render-as-markdown-0.0.2.gem +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGU0Zjg0ZGRlYjJkOGJiNDg4ZDkwNTM4NmMzOWNiNGRjYTQzYmU4OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzEyZTI2OWNmZGE5NmUwYzI3MDk3NGI1NDY2YTVmYWNjMTcyMGU4Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWJjZTM3YjNiOGZlZDg4N2EwMGQ4ZGNhMTg0MjNlZjcyYzc3NjVmMGFkNDgw
|
10
|
+
OTI3NmY3NjgwMGMyNTk3ODU1NDZlZmVmZGVmNTNhZWMzM2Y5NmZkZTY4OTM2
|
11
|
+
ZDVkODM0YTVjMjUwN2I1MDYzOWUxMThlZWRmODEyM2FlOWJjNjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTUwYjQzODliZGJkMGEyMzMwMzFiODA0MjdkOTI5OWFkYWZlOGI2YTE0NTMy
|
14
|
+
NzFmNGZhMWE3ZDU3ZjNlMGM5MWE0ZGU5MzQ2ZmFjOTlmODI0OTI3NDRlZGI4
|
15
|
+
MWE5ZTQ4NDFmMGRkYTI0MDEzZDhjNWQwMWU2YmQ1OWU4OWMzOWE=
|
data/HISTORY.md
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
HISTORY
|
2
2
|
=======
|
3
3
|
|
4
|
+
[2012-10-16]
|
5
|
+
- Readme: what is Markdown?
|
6
|
+
- added Link class
|
7
|
+
- added Image class
|
8
|
+
|
9
|
+
[2012-10-15]
|
10
|
+
- added List class
|
11
|
+
- added simple Code class with 4 spaces indentation
|
12
|
+
|
4
13
|
[2013-10-13]
|
5
|
-
- wrote tests (nil, Numbers, etc)
|
6
|
-
- wrote classes for H1 and H2
|
14
|
+
- wrote tests for Table class and fixed problems (nil, Numbers, etc)
|
15
|
+
- wrote classes and tests for H1 and H2 with Markdown underline notation (h1: ===, h2: ----)
|
16
|
+
- v0.0.4
|
7
17
|
|
8
18
|
[2013-10-06]
|
9
19
|
- some bugfixes
|
data/README.md
CHANGED
@@ -1,12 +1,78 @@
|
|
1
|
-
|
1
|
+
RenderAsMarkdown
|
2
|
+
================
|
2
3
|
|
3
|
-
RenderAsMarkdown is a small Ruby gem featuring simple to use
|
4
|
+
RenderAsMarkdown is a small Ruby gem featuring simple to use classes to turn
|
5
|
+
data into Markdown.
|
4
6
|
|
5
|
-
|
7
|
+
This project started when [rmetzler](//github.com/rmetzler) tried to render
|
8
|
+
data into a Markdown table. While this was easy to achive with templating, a
|
9
|
+
dedicated helper gem was more reuseable and produced output that was also
|
10
|
+
easier to scan in ASCII.
|
6
11
|
|
7
|
-
|
12
|
+
Ultimately this helper should turn into something like a DSL to create and
|
13
|
+
scaffold Markdown documents. In particular it should be very useful to create
|
14
|
+
project documentation files like README.md, TODO.md, LICENSE.md, etc. with it.
|
15
|
+
Github is able to render Markdown as HTML so automatically generated project
|
16
|
+
documentation could be displayed on http://github.com
|
8
17
|
|
9
|
-
|
18
|
+
See [Implementation](#implementation) for what's implemented yet.
|
19
|
+
|
20
|
+
|
21
|
+
What is Markdown?
|
22
|
+
-----------------
|
23
|
+
|
24
|
+
Markdown is a (supposed to be) simple markup language that can be written and
|
25
|
+
converted into HTML easily.
|
26
|
+
|
27
|
+
It was [created by John Gruber in December 2004](http://daringfireball.net/projects/markdown/)
|
28
|
+
and has grown in popularity since. Developers started to adapt Markdown and
|
29
|
+
several different Markdown dialects emerged:
|
30
|
+
|
31
|
+
- [Original Markdown Syntax](http://daringfireball.net/projects/markdown/syntax)
|
32
|
+
- [Github created Github flavored Markdown](http://github.github.com/github-flavored-markdown/)
|
33
|
+
- [MultiMarkdown adds features for multiple files](http://fletcherpenney.net/multimarkdown/)
|
34
|
+
- [iA Writer uses a slightly different dialect](http://support.iawriter.com/help/kb/general-questions/markdown-syntax-reference-guide)
|
35
|
+
|
36
|
+
|
37
|
+
Implementation
|
38
|
+
--------------
|
39
|
+
|
40
|
+
### Headers
|
41
|
+
|
42
|
+
Headers in Markdown can be written in two different notations. the #-Notation
|
43
|
+
where you just prepend # for H1, ## for H2, ### for H3 ... up to H5.
|
44
|
+
You get the concept.
|
45
|
+
|
46
|
+
And there is the underline Notation for H1 (===) and H2 (---). This notation
|
47
|
+
is easier to scan in ASCII files, but its not as simple to implement in
|
48
|
+
Markdown templates as the #-notation is. So I wrote two little helpers classes.
|
49
|
+
|
50
|
+
|
51
|
+
### Link
|
52
|
+
|
53
|
+
Links in Markdown have a URL, text (optional) and hint (optional).
|
54
|
+
|
55
|
+
### Image
|
56
|
+
|
57
|
+
Images in Markdown have a URL, an alt text and a hint (optional).
|
58
|
+
|
59
|
+
|
60
|
+
### List
|
61
|
+
|
62
|
+
Lists in Markdown start with a dash and a space in every line.
|
63
|
+
|
64
|
+
|
65
|
+
### Code
|
66
|
+
|
67
|
+
There are different notations for Code in Markdown.
|
68
|
+
Currently the implementation just indent every line by 4 spaces.
|
69
|
+
|
70
|
+
|
71
|
+
### Table
|
72
|
+
|
73
|
+
It's really easy to render a table in (GHf)MD, but the simplest approach
|
74
|
+
doesn't look that nice in raw mode. That's why there is this simple class,
|
75
|
+
tables work in the terminal AND on Github.
|
10
76
|
|
11
77
|
```Ruby
|
12
78
|
t = RenderMarkdown::Table.new %w{eins zwei superkalifrageristric}
|
@@ -19,11 +85,11 @@ renders the following table
|
|
19
85
|
```
|
20
86
|
eins |zwei|superkalifrageristric
|
21
87
|
------------------|----|---------------------
|
22
|
-
hoch-soll-er-leben|3 |mal-hoch
|
88
|
+
hoch-soll-er-leben|3 |mal-hoch
|
23
89
|
```
|
24
90
|
|
25
91
|
Thanks to Github, this is also rendered in HTML. Nice!
|
26
92
|
|
27
93
|
eins |zwei|superkalifrageristric
|
28
94
|
------------------|----|---------------------
|
29
|
-
hoch-soll-er-leben|3 |mal-hoch
|
95
|
+
hoch-soll-er-leben|3 |mal-hoch
|
data/TODO.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# TODO
|
2
2
|
|
3
|
-
-
|
4
|
-
- create a Image class Image.new(src, alt="" )
|
5
|
-
- create H1 and H2 classes that use Markdown underline notation (h1: ====, h2: ----)
|
6
|
-
- create List class
|
3
|
+
- rename files (markdown-heder.rb -> header.rb)
|
7
4
|
- create DSL methods like table(titles) instead of Table.new
|
5
|
+
- Readme: better examples
|
6
|
+
- create example folder
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RenderAsMarkdown
|
2
|
+
class Image
|
3
|
+
|
4
|
+
attr_accessor :alt_text, :url, :title
|
5
|
+
|
6
|
+
def initialize alt_text, url, title=nil
|
7
|
+
@alt_text, @url, @title = alt_text.to_s, url.to_s, title.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def render
|
11
|
+
title = " \"#{@title}\"" unless @title.empty?
|
12
|
+
""
|
13
|
+
end
|
14
|
+
|
15
|
+
alias_method :to_s, :render
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RenderAsMarkdown
|
2
|
+
class Link
|
3
|
+
|
4
|
+
# TODO: look up Github in-document link reference and implement it (e.g. "[A Header](#a-header)" )
|
5
|
+
|
6
|
+
attr_accessor :url, :text, :hint
|
7
|
+
|
8
|
+
def initialize url, text=nil, hint=nil
|
9
|
+
@url, @text, @hint = url.to_s, text.to_s, hint.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def render
|
13
|
+
text = @text.empty? ? @url : @text
|
14
|
+
hint = " \"#{@hint}\"" unless @hint.empty?
|
15
|
+
"[#{text}](#{@url}#{hint})"
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :to_s, :render
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RenderAsMarkdown
|
2
|
+
class Code
|
3
|
+
|
4
|
+
attr_accessor :code
|
5
|
+
|
6
|
+
def initialize code
|
7
|
+
# list_items will be an array
|
8
|
+
@code = code.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def render
|
12
|
+
md = ''
|
13
|
+
@code.lines.each {|l| md << " " << l }
|
14
|
+
md
|
15
|
+
end
|
16
|
+
|
17
|
+
alias_method :to_s, :render
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RenderAsMarkdown
|
2
|
+
class List
|
3
|
+
|
4
|
+
attr_accessor :list_items
|
5
|
+
|
6
|
+
def initialize list_items
|
7
|
+
# list_items will be an array
|
8
|
+
@list_items = [*list_items]
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_list_item list_item
|
12
|
+
# concat arrays
|
13
|
+
list_items.concat [*list_item]
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method '<<', :add_list_item
|
17
|
+
|
18
|
+
def render
|
19
|
+
md = ''
|
20
|
+
|
21
|
+
@list_items.each do |item|
|
22
|
+
md << "- #{item.to_s}\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
md
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_method :to_s, :render
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/render-as-markdown.rb
CHANGED
@@ -1,2 +1,6 @@
|
|
1
|
-
require File.expand_path
|
2
|
-
require File.expand_path
|
1
|
+
require File.expand_path '../render-as-markdown/markdown-table', __FILE__
|
2
|
+
require File.expand_path '../render-as-markdown/markdown-header', __FILE__
|
3
|
+
require File.expand_path '../render-as-markdown/markdown-list', __FILE__
|
4
|
+
require File.expand_path '../render-as-markdown/markdown-code', __FILE__
|
5
|
+
require File.expand_path '../render-as-markdown/link', __FILE__
|
6
|
+
require File.expand_path '../render-as-markdown/image', __FILE__
|
data/test/code_test.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
module RenderAsMarkdown
|
4
|
+
class CodeTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_simple_list
|
7
|
+
l = RenderAsMarkdown::Code.new <<-eos
|
8
|
+
a
|
9
|
+
b
|
10
|
+
c
|
11
|
+
d
|
12
|
+
eos
|
13
|
+
assert_equal l.render, \
|
14
|
+
" a\n"+
|
15
|
+
" b\n"+
|
16
|
+
" c\n"+
|
17
|
+
" d\n"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/test/image_test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
module RenderAsMarkdown
|
4
|
+
class ImageTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_image
|
7
|
+
l = RenderAsMarkdown::Image.new "Alt Text", "http://whatismarkdown.com/workspace/img/logo.gif"
|
8
|
+
assert_equal "", l.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_image_with_title
|
12
|
+
l = RenderAsMarkdown::Image.new "Alt Text", "http://whatismarkdown.com/workspace/img/logo.gif", "Markdown Logo"
|
13
|
+
assert_equal "", l.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
data/test/link_test.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
module RenderAsMarkdown
|
4
|
+
class ListTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_link_url_only
|
7
|
+
l = RenderAsMarkdown::Link.new "https://google.com/"
|
8
|
+
assert_equal "[https://google.com/](https://google.com/)", l.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_link_text_url
|
12
|
+
l = RenderAsMarkdown::Link.new "https://google.com/", "google it"
|
13
|
+
assert_equal "[google it](https://google.com/)", l.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_link_text_url_hint
|
17
|
+
l = RenderAsMarkdown::Link.new "https://google.com/", "google it", "Google Search"
|
18
|
+
assert_equal '[google it](https://google.com/ "Google Search")', l.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/test/list_test.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
module RenderAsMarkdown
|
4
|
+
class ListTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_simple_list
|
7
|
+
l = RenderAsMarkdown::List.new ['first entry', 'second entry']
|
8
|
+
l << 'third entry'
|
9
|
+
|
10
|
+
assert_equal l.render, \
|
11
|
+
"- first entry\n"+
|
12
|
+
"- second entry\n"+
|
13
|
+
"- third entry\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render-as-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Metzler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,13 +83,20 @@ files:
|
|
83
83
|
- TODO.md
|
84
84
|
- lib/render-as-markdown.rb
|
85
85
|
- lib/render-as-markdown/dsl.rb
|
86
|
+
- lib/render-as-markdown/image.rb
|
87
|
+
- lib/render-as-markdown/link.rb
|
88
|
+
- lib/render-as-markdown/markdown-code.rb
|
86
89
|
- lib/render-as-markdown/markdown-header.rb
|
90
|
+
- lib/render-as-markdown/markdown-list.rb
|
87
91
|
- lib/render-as-markdown/markdown-table.rb
|
88
92
|
- lib/render-as-markdown/md-link.rb
|
89
93
|
- lib/render-as-markdown/version.rb
|
90
|
-
- render-as-markdown-0.0.2.gem
|
91
94
|
- render-as-markdown.gemspec
|
95
|
+
- test/code_test.rb
|
92
96
|
- test/header_test.rb
|
97
|
+
- test/image_test.rb
|
98
|
+
- test/link_test.rb
|
99
|
+
- test/list_test.rb
|
93
100
|
- test/minitest_helper.rb
|
94
101
|
- test/table_test.rb
|
95
102
|
homepage: https://github.com/rmetzler/render-as-markdown
|
@@ -118,6 +125,10 @@ specification_version: 4
|
|
118
125
|
summary: Currently implemented is a table in GitHub-flavoured Markdown. It works perfectly
|
119
126
|
fine, but is not fully featured yet.
|
120
127
|
test_files:
|
128
|
+
- test/code_test.rb
|
121
129
|
- test/header_test.rb
|
130
|
+
- test/image_test.rb
|
131
|
+
- test/link_test.rb
|
132
|
+
- test/list_test.rb
|
122
133
|
- test/minitest_helper.rb
|
123
134
|
- test/table_test.rb
|
Binary file
|