render-as-markdown 0.0.3 → 0.0.4

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTA4MzNmZDYwZGY0ZTRhMTA5MWRjOTFhNmRkY2Q4NzA3M2YyZWY4OA==
4
+ NTUxZGM5M2UyYzE2NzYwMDdmN2IxNDY3YWFiZTAwODUyNjIxZTQzYg==
5
5
  data.tar.gz: !binary |-
6
- MWYyMTQ4OGJhNjZmNDk5ZTZhM2MxZTlhMDZkMTAyZGY5MWM2ZTkwNA==
6
+ OGNiM2M0MTQxZmVlOWMwN2Y5MjhmZThkMjlhMTZjYzY0YTM5ZDdhMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTM5NDk3NmEzMDU4ODQ5MmZkZDIxMGE4ZmYxMDIwNTVmMTBmOGRiNThkYWIy
10
- OTU0MzY4YzU4MWU0MmM5NWE1ODdmZWM0MGMyZDE4MTE4ZTBmNDcyY2JiZDkx
11
- MTI0ZmQ3Y2IxZDAwODAzMWRkNGZiMTUwZTcyOTM1ZDRiNWExYjI=
9
+ Y2RjYzExODFhZDNlYjdhNzgyYzEyZjc1YzllMTg3NWZlMThkYTZhOTE4NmVj
10
+ M2Y4M2Q3ZTAwZTc3OTg0ZDkzYjE5OWVjZjA0MzQ4MTkyYmRlYTNmNTFhNDg2
11
+ Y2JkYjhkZTY1ZTgxNDJjZTQwN2Q3YThkOTFiYzg3ZGVlZmEwZmI=
12
12
  data.tar.gz: !binary |-
13
- OTNlMWYxODY2NDQyODRkNjBmZWY5OGVmYTIxYTM5OWJmYTk0OGJjYTllNmI5
14
- NjM4YmQyYWZmNGEwOWYxNzg5NGRjMjlhNmU2MTdhNWNhYzlkZTBhOGE0NGE2
15
- ZWUzNzNiMTQ5NzY3YTQ4M2QxZmMxOWY1Nzc2ODlmYmE1MjM4N2I=
13
+ ODdmYmIxYmE1Y2YyZjAwOWZhNWM1MGI5MmUyYzFiZTFkOTY5YzkyYmM5NjM5
14
+ ZjcyMjZmZWY4ZTQ5OGYyZDRkMjBmYTVlOGJiN2MxOTVmNTFjNGFlOTk5YThm
15
+ M2QzN2E5YzI0OGRlNGYyMzIyYjlhZTlmYzkwZjExMDA4NjU1NGY=
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ Gemfile.lock
data/HISTORY.md ADDED
@@ -0,0 +1,12 @@
1
+ HISTORY
2
+ =======
3
+
4
+ [2013-10-13]
5
+ - wrote tests (nil, Numbers, etc)
6
+ - wrote classes for H1 and H2
7
+
8
+ [2013-10-06]
9
+ - some bugfixes
10
+
11
+ [2013-10-06]
12
+ - created gem render-as-markdown, because I wanted a better Table for GitHub and GitHub renders Markdown pretty well
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Richard Metzler
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/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.pattern = "test/**/*_test.rb"
7
+ end
8
+
9
+ task :default => :test
data/TODO.md ADDED
@@ -0,0 +1,7 @@
1
+ # TODO
2
+
3
+ - create a Link class Link.new(url, text, hint="")
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
7
+ - create DSL methods like table(titles) instead of Table.new
@@ -0,0 +1,15 @@
1
+ module RenderAsMarkdown
2
+ class MD
3
+
4
+ def table
5
+
6
+ end
7
+
8
+ def h1
9
+ end
10
+
11
+ def h2
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ module RenderAsMarkdown
2
+ class Header
3
+
4
+ def initialize title, char
5
+ @title = [title.to_s.strip, " "].max
6
+ @char = char.to_s
7
+ end
8
+
9
+ def render
10
+ length = [@title.length, 1].max
11
+ @title << "\n" << @char*length << "\n"*2
12
+ end
13
+
14
+ alias_method :to_s, :render
15
+ end
16
+
17
+ class H1 < Header
18
+
19
+ def initialize title
20
+ super title, "="
21
+ end
22
+
23
+ end
24
+
25
+ class H2 < Header
26
+
27
+ def initialize title
28
+ super title, "-"
29
+ end
30
+
31
+ end
32
+ end
@@ -3,19 +3,23 @@ module RenderAsMarkdown
3
3
 
4
4
  attr_accessor :columns, :rows
5
5
 
6
- def initialize column_titles = []
7
- @columns = column_titles.map{|title| Column.new title}
6
+ def initialize column_titles
7
+ # column_titles will be an array
8
+ @columns = [*column_titles].map{|title| Column.new title}
8
9
  @rows = []
9
10
  end
10
11
 
11
12
  def add_row row
12
13
  # TODO: ensure element count of row is == element count of columns
13
14
 
14
- # add row to rows
15
+ # make row an array
16
+ row = [*row]
17
+
18
+ # add row to rows, use an array
15
19
  @rows << row
16
20
 
17
21
  # iterate through columns and row, add each row to their column
18
- @columns.zip(row).each {|col, string| col.add_row string}
22
+ @columns.zip(row).each {|col, val| col.add_row val.to_s}
19
23
  end
20
24
 
21
25
  alias_method '<<', :add_row
@@ -35,6 +39,9 @@ module RenderAsMarkdown
35
39
  # return table
36
40
  table
37
41
  end
42
+
43
+ alias_method :to_s, :render
44
+
38
45
  end
39
46
 
40
47
 
@@ -44,8 +51,8 @@ module RenderAsMarkdown
44
51
 
45
52
  def initialize title
46
53
  @rows = []
47
- @title = title
48
- @width = title.to_s.length
54
+ @title = title.to_s
55
+ @width = [@title.length, 1].max
49
56
  end
50
57
 
51
58
  def render_title
@@ -0,0 +1,11 @@
1
+ module RenderAsMarkdown
2
+ class Link
3
+
4
+ attr_accessor :columns, :rows
5
+
6
+ def initialize url, text, hint=''
7
+ end
8
+
9
+
10
+ end
11
+
@@ -1,6 +1,6 @@
1
1
  module RenderAsMarkdown
2
- GEM = 'render-as-markdown'
3
- VERSION = '0.0.3'
2
+ GEM = 'render-as-markdown'
3
+ VERSION = '0.0.4'
4
4
  end
5
5
 
6
- puts "This is version #{RenderAsMarkdown::VERSION} of gem #{RenderAsMarkdown::GEM}"
6
+ #puts "This is version #{RenderAsMarkdown::VERSION} of gem #{RenderAsMarkdown::GEM}"
@@ -1 +1,2 @@
1
1
  require File.expand_path('../render-as-markdown/markdown-table', __FILE__)
2
+ require File.expand_path('../render-as-markdown/markdown-header', __FILE__)
@@ -18,7 +18,11 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
  gem.version = RenderAsMarkdown::VERSION
20
20
 
21
+ gem.add_development_dependency 'bundler'
21
22
  gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'minitest'
24
+ gem.add_development_dependency 'minitest-reporters'
25
+ # gem.add_development_dependency 'sandi_meter'
22
26
 
23
27
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
28
  gem.files = `git ls-files`.split("\n")
@@ -0,0 +1,36 @@
1
+ require 'minitest_helper'
2
+
3
+ module RenderAsMarkdown
4
+ class TableTest < MiniTest::Unit::TestCase
5
+
6
+ def test_h1
7
+ h1 = RenderAsMarkdown::H1.new 'header 1'
8
+ assert_equal h1.to_s, <<-eos
9
+ header 1
10
+ ========
11
+
12
+ eos
13
+ end
14
+
15
+ def test_h2
16
+ h2 = RenderAsMarkdown::H2.new 'header 2'
17
+ assert_equal h2.to_s, <<-eos
18
+ header 2
19
+ --------
20
+
21
+ eos
22
+ end
23
+
24
+
25
+ def test_strip_spaces
26
+ # we have to make sure, not to underline spaces
27
+ h1 = RenderAsMarkdown::H1.new ' <!-- spaces --> '
28
+ assert_equal h1.render, <<-eos
29
+ <!-- spaces -->
30
+ ===============
31
+
32
+ eos
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ require "minitest/autorun"
2
+
3
+ require "minitest/reporters"
4
+ Minitest::Reporters.use!
5
+
6
+ require_relative '../lib/render-as-markdown'
@@ -0,0 +1,80 @@
1
+ require 'minitest_helper'
2
+
3
+ # I'm sorry, I concat Ruby strings
4
+ # the reason is: the table ends with spaces
5
+ # and whenever I hit cmd+s, a textmate plugin
6
+ # deletes all trailing spaces in my file
7
+
8
+ module RenderAsMarkdown
9
+ class TableTest < MiniTest::Unit::TestCase
10
+
11
+ def test_simple_table
12
+ t = RenderAsMarkdown::Table.new %w{eins zwei superkalifrageristric}
13
+ t << %w{hoch-soll-er-leben 3 mal-hoch}
14
+
15
+ assert_equal t.render, \
16
+ "eins |zwei|superkalifrageristric\n"+
17
+ "------------------|----|---------------------\n"+
18
+ "hoch-soll-er-leben|3 |mal-hoch \n"
19
+
20
+ end
21
+
22
+ def test_header_with_numbers
23
+ header = [1,2,3]
24
+ t = RenderAsMarkdown::Table.new header
25
+ t << [3,2,1]
26
+ t << [4,5,6]
27
+
28
+ assert_equal t.render, \
29
+ "1|2|3\n"+
30
+ "-|-|-\n"+
31
+ "3|2|1\n"+
32
+ "4|5|6\n"
33
+
34
+ end
35
+
36
+ def test_numbers
37
+ header = [1,2,3]
38
+ t = RenderAsMarkdown::Table.new header
39
+ t << [3,2,1]
40
+ t << [4,5,6]
41
+
42
+ assert_equal t.render, \
43
+ "1|2|3\n"+
44
+ "-|-|-\n"+
45
+ "3|2|1\n"+
46
+ "4|5|6\n"
47
+
48
+ end
49
+
50
+ def test_nil
51
+ header = [nil, "eins", "zwei"]
52
+ t = RenderAsMarkdown::Table.new header
53
+ t << [nil, 1, 2]
54
+
55
+ assert_equal t.render, \
56
+ " |eins|zwei\n"+
57
+ "-|----|----\n"+
58
+ " |1 |2 \n"
59
+ end
60
+
61
+
62
+ def test_single_column
63
+ t = RenderAsMarkdown::Table.new "nr"
64
+ t << 1
65
+ t << 2
66
+ t << 3
67
+ t << 4
68
+
69
+ assert_equal t.render,
70
+ "nr\n"+
71
+ "--\n"+
72
+ "1 \n"+
73
+ "2 \n"+
74
+ "3 \n"+
75
+ "4 \n"
76
+ end
77
+
78
+
79
+ end
80
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render-as-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-06 00:00:00.000000000 Z
11
+ date: 2013-10-13 00:00:00.000000000 Z
12
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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,34 @@ dependencies:
24
38
  - - ! '>='
25
39
  - !ruby/object:Gem::Version
26
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: '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: minitest-reporters
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'
27
69
  description: ! "\n RenderAsMarkdown is a small Ruby gem featuring simple to use
28
70
  objects to turn data into Markdown.\n "
29
71
  email:
@@ -32,14 +74,24 @@ executables: []
32
74
  extensions: []
33
75
  extra_rdoc_files: []
34
76
  files:
77
+ - .gitignore
35
78
  - Gemfile
79
+ - HISTORY.md
80
+ - LICENSE.txt
36
81
  - README.md
82
+ - Rakefile
83
+ - TODO.md
37
84
  - lib/render-as-markdown.rb
85
+ - lib/render-as-markdown/dsl.rb
86
+ - lib/render-as-markdown/markdown-header.rb
38
87
  - lib/render-as-markdown/markdown-table.rb
88
+ - lib/render-as-markdown/md-link.rb
39
89
  - lib/render-as-markdown/version.rb
40
- - render-as-markdown-0.0.1.gem
41
90
  - render-as-markdown-0.0.2.gem
42
91
  - render-as-markdown.gemspec
92
+ - test/header_test.rb
93
+ - test/minitest_helper.rb
94
+ - test/table_test.rb
43
95
  homepage: https://github.com/rmetzler/render-as-markdown
44
96
  licenses:
45
97
  - MIT
@@ -65,5 +117,7 @@ signing_key:
65
117
  specification_version: 4
66
118
  summary: Currently implemented is a table in GitHub-flavoured Markdown. It works perfectly
67
119
  fine, but is not fully featured yet.
68
- test_files: []
69
- has_rdoc:
120
+ test_files:
121
+ - test/header_test.rb
122
+ - test/minitest_helper.rb
123
+ - test/table_test.rb
Binary file