render-as-markdown 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjQxMzFmMzFhNzM4ZGM1Yjg3MzhiZDk0MDY3ZDZkNWU3ZDkyZDJiZA==
5
+ data.tar.gz: !binary |-
6
+ M2NiNzRkNmI5ZDIwOGMyMTI5NzY0ZGY0YzBkZGQ4NjFiODYzNTFjYw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NmRhYjQzODk3OTJjMjEwYWU4MDM4YzdiN2EyNjNiNWM5MjMwOTQ5NmRlYjVj
10
+ NzdiNWY0YWVmYWQzNTFjOWE5YjJhNTE4OWU3ZDQ3N2UyODMyMzhmODA5ZDU5
11
+ YzRjZjcyMzRhNjI2YTZjMWMwNDMxZmZlMDg5NTRhZjk4MjJmZmI=
12
+ data.tar.gz: !binary |-
13
+ OTYxY2VkMzJkYzE0NTY0MDI3NGQ5N2E4YTZhOWY1NTdkNmFhMjhhYzU0OTM0
14
+ MWIxYjJkMTQzZTc0OWFlZThjNjNjMzc2MzdhNTZjNmY1NzE1NDUyODcwNWQy
15
+ MjdlMTNmN2IzZmM1ZmNlMzUwYTYyNzJhN2Y2MDg3ODA1ZTk1MTU=
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ #RenderAsMarkdown
2
+
3
+ RenderAsMarkdown is a small Ruby gem featuring simple to use objects to turn data into Markdown.
4
+
5
+ Currently implemented is a table in GitHub-flavoured Markdown. It's not fully featured yet.
6
+
7
+ ## Table
8
+
9
+ It's really easy to render a table in (GHf)MD, but the simplest approach doesn't look that nice in raw mode. That's why there is this simple class, tables work in the terminal AND on Github.
10
+
11
+ ```Ruby
12
+ t = RenderMarkdown::Table.new %w{eins zwei superkalifrageristric}
13
+ t << %w{hoch-soll-er-leben 3 mal-hoch}
14
+ puts t.render
15
+ ```
16
+
17
+ renders the following table
18
+
19
+ ```
20
+ eins |zwei|superkalifrageristric
21
+ ------------------|----|---------------------
22
+ hoch-soll-er-leben|3 |mal-hoch
23
+ ```
24
+
25
+ Thanks to Github, this is also rendered in HTML. Nice!
26
+
27
+ eins |zwei|superkalifrageristric
28
+ ------------------|----|---------------------
29
+ hoch-soll-er-leben|3 |mal-hoch
@@ -0,0 +1,74 @@
1
+ module RenderAsMarkdown
2
+ class Table
3
+
4
+ attr_accessor :columns, :rows
5
+
6
+ def initialize column_titles = []
7
+ @columns = column_titles.map{|title| Column.new title}
8
+ @rows = []
9
+ end
10
+
11
+ def add_row row
12
+ # TODO: ensure element count of row is == element count of columns
13
+
14
+ # add row to rows
15
+ @rows << row
16
+
17
+ # iterate through columns and row, add each row to their column
18
+ @columns.zip(row).each {|col, string| col.add_row string}
19
+ end
20
+
21
+ alias_method '<<', :add_row
22
+
23
+ def render
24
+ # join all column headers
25
+ table = @columns.map(&:render_title).join( '|' ) << "\n"
26
+
27
+ # join all column lines
28
+ table << @columns.map(&:render_line).join( '|' ) << "\n"
29
+
30
+ # join all columns for all rows
31
+ @rows.each_with_index do |row, i|
32
+ table << @columns.map {|col| col.render_row i}.join( '|' ) << "\n"
33
+ end
34
+
35
+ # return table
36
+ table
37
+ end
38
+ end
39
+
40
+
41
+ class Column
42
+
43
+ attr_accessor :title, :width, :rows
44
+
45
+ def initialize title
46
+ self.rows = []
47
+ self.title = title
48
+ self.width = title.length
49
+ end
50
+
51
+ def render_title
52
+ @title.ljust @width
53
+ end
54
+
55
+ def render_line
56
+ '-'.ljust @width, '-'
57
+ end
58
+
59
+ def render_row row_number
60
+ @rows[row_number].ljust @width
61
+ end
62
+
63
+ def add_row string
64
+ self.rows << string
65
+ self.update_width string.length
66
+ end
67
+
68
+ def update_width length
69
+ @width = length if @width < length
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,6 @@
1
+ module RenderAsMarkdown
2
+ GEM = 'render-as-markdown'
3
+ VERSION = '0.0.2'
4
+ end
5
+
6
+ puts "This is version #{RenderAsMarkdown::VERSION} of gem #{RenderAsMarkdown::GEM}"
@@ -0,0 +1 @@
1
+ require File.expand_path('../render-as-markdown/markdown-table', __FILE__)
Binary file
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/render-as-markdown/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Richard Metzler"]
6
+ gem.email = ["richard@launchco.com"]
7
+ gem.description = %q{
8
+ RenderAsMarkdown is a small Ruby gem featuring simple to use objects to turn data into Markdown.
9
+ }
10
+ gem.summary = %q{
11
+ Currently implemented is a table in GitHub-flavoured Markdown.
12
+ It works perfectly fine, but is not fully featured yet.
13
+ }
14
+ gem.homepage = "https://github.com/rmetzler/render-as-markdown"
15
+ gem.license = "MIT"
16
+
17
+ gem.name = "render-as-markdown"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = RenderAsMarkdown::VERSION
20
+
21
+ gem.add_development_dependency 'rake'
22
+
23
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ gem.files = `git ls-files`.split("\n")
25
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: render-as-markdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Richard Metzler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
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'
27
+ description: ! "\n RenderAsMarkdown is a small Ruby gem featuring simple to use
28
+ objects to turn data into Markdown.\n "
29
+ email:
30
+ - richard@launchco.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - Gemfile
36
+ - README.md
37
+ - lib/render-as-markdown.rb
38
+ - lib/render-as-markdown/markdown-table.rb
39
+ - lib/render-as-markdown/version.rb
40
+ - render-as-markdown-0.0.1.gem
41
+ - render-as-markdown.gemspec
42
+ homepage: https://github.com/rmetzler/render-as-markdown
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.1.5
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Currently implemented is a table in GitHub-flavoured Markdown. It works perfectly
66
+ fine, but is not fully featured yet.
67
+ test_files: []
68
+ has_rdoc: