fluent_markdown_builder 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d5d82d0aecb2d8e3a806de7b768061c80674da1e6345dd4fca5b1241d34775ac
4
+ data.tar.gz: 20cd19c395244dc3e61b3123b83d1ac9dc6704471b5ded81c0d8c4c7ff7eca21
5
+ SHA512:
6
+ metadata.gz: f1fec3cc3158b6de2795cb40ae59ab37de6fb320e3db723605303739c5de4ce2229dd3b7e648c73c0e62b272d7abfea0bc43cfe321832f5a11df1d3f9986fe9b
7
+ data.tar.gz: e5bff018b386944b3e55da75f82b7b0d993e5c74a1370b89da8b090d261d44824e065a408fa1a597e68c110b2ee919e4af1109c41231b637e0efcc9af3cd26c9
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.swp
10
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fluent_markdown_builder.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Niklas Schultz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Fluent Markdown Builder
2
+
3
+ The fluent markdown builder is a ruby gem which provides a fluent interface
4
+ for creating markdown content.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'fluent_markdown_builder'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install fluent_markdown_builder
21
+
22
+ ## Usage
23
+
24
+ This gem only has one file intended to be used by the client: The Markdown.rb
25
+
26
+ You can simply create an object from this class and start building your markdown
27
+ content like the following example demonstrates:
28
+
29
+ ```ruby
30
+ md = Markdown.new('The fluent markdown builder gem')
31
+ .text('This is a gem which allows you to generate markdown syntax')
32
+ .text(' via a fluent builder pattern.')
33
+ .new_line
34
+ .text('Let\'s show some more functionality')
35
+ .new_line
36
+ .header(2, 'Lists')
37
+ .text('There are two type of lists:')
38
+ .paragraph
39
+ .bold('Organized lists:')
40
+ .new_line
41
+ .ol(['Some item', 'Another item', 'And yet another item'])
42
+ .bold('Unorganized lists:')
43
+ .new_line
44
+ .ul(['More items!', 'And even more', '...'])
45
+ .header(2, 'Hyperlinks')
46
+ .cursive('You can also add hyperlinks:')
47
+ .new_line
48
+ .hyperlink('Link to google', 'https://www.google.com', 'Take me to google')
49
+ .paragraph
50
+ .header(2, 'Code')
51
+ .text('We can also add code snippets')
52
+ .new_line
53
+ .code('#define 1 0')
54
+ .paragraph
55
+ .horizontal_line
56
+ .cursive('I think that should be enough for a short demo')
57
+ .new_line
58
+ .quote('Have a nice day')
59
+ .to_s
60
+ ```
61
+
62
+ Now you can write the (string) content into a file for example and display it in
63
+ a markdown viewer.
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags.
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are very welcome and highly appreciated
74
+ on GitHub at https://github.com/SNException/fluent_markdown_builder.
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent_markdown_builder"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "core/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluent_markdown_builder"
8
+ spec.version = FluentMarkdownBuilder::VERSION
9
+ spec.authors = ["Niklas Schultz"]
10
+ spec.email = ["thexsalkin@gmail.com"]
11
+
12
+ spec.summary = 'A fluent markdown builder'
13
+ spec.description = 'A fluent interface to generate markdown easily.'
14
+ spec.homepage = 'https://github.com/SNException/fluent_markdown_builder'
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.10"
29
+ end
@@ -0,0 +1,166 @@
1
+ # MIT License
2
+ #
3
+ # Copyright 2019 Niklas Schultz.
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ # The Markdown object.
24
+ # All its methods (with the exception of to_s) return 'self'.
25
+ # That way you can use this object as fluent builder to create your
26
+ # Markdown content.
27
+ #
28
+ # author:: Niklas Schultz
29
+ # version:: 0.1.0
30
+ # license:: MII
31
+ class Markdown
32
+ # Creates a new object.
33
+ #
34
+ # You can ignore the argument so no header will be added on construction of
35
+ # this object.
36
+ def initialize(h1 = '')
37
+ @md = ''
38
+ unless h1.empty? then header(1, h1) end
39
+ end
40
+
41
+ # Adds a string to the current content.
42
+ def text(txt)
43
+ @md += txt
44
+ self
45
+ end
46
+
47
+ # Adds a header to the markdown content.
48
+ #
49
+ # The first argument specifies the header level (h1, h2...h6).
50
+ def header(level, txt)
51
+ raise ArgumentError, 'header level must not be 0 or smaller' if level <= 0
52
+ raise ArgumentError, 'header level must not be greater than 6' if level > 6
53
+
54
+ hashes = ''
55
+ level.times do
56
+ hashes += '#'
57
+ end
58
+ text(hashes + ' ' + txt)
59
+ paragraph
60
+ end
61
+
62
+ # Adds a horizontal line.
63
+ def horizontal_line
64
+ text('---')
65
+ paragraph
66
+ end
67
+
68
+ # Adds text which is cursive.
69
+ def cursive(txt)
70
+ text('*' + txt.rstrip.lstrip + '*')
71
+ end
72
+
73
+ # Adds text which is bold.
74
+ def bold(txt)
75
+ text('**' + txt.rstrip.lstrip + '**')
76
+ end
77
+
78
+ # Adds text which is both bold and cursive.
79
+ def bold_and_cursive(txt)
80
+ text('***' + txt.rstrip.lstrip + '***')
81
+ end
82
+
83
+ # Adds a quote.
84
+ def quote(txt)
85
+ text('> ' + txt)
86
+ end
87
+
88
+ # Adds a line of code.
89
+ def code(txt)
90
+ text('`' + txt + '`')
91
+ end
92
+
93
+ # Adds an unorganized list out of the given array.
94
+ def ul(bullet_points)
95
+ unless bullet_points.respond_to?(:each)
96
+ raise ArgumentError, 'arg must respond to "each" call'
97
+ end
98
+
99
+ md_list = ''
100
+ bullet_points.each do |v|
101
+ md_list += '* ' + v + line_feed
102
+ end
103
+ text(md_list)
104
+ paragraph
105
+ end
106
+
107
+ # Adds an organized list out of the given array.
108
+ def ol(bullet_points)
109
+ unless bullet_points.respond_to?(:each_with_index)
110
+ raise ArgumentError, 'arg must respond to "each_width_index" call'
111
+ end
112
+
113
+ md_list = ''
114
+ bullet_points.each_with_index do |v, i|
115
+ md_list += (i + 1).to_s + '. ' + v + line_feed
116
+ end
117
+ text(md_list)
118
+ paragraph
119
+ end
120
+
121
+ # Adds a hyperlink.
122
+ #
123
+ # This method takes three arguments:
124
+ # 1. The description of the hyperlink (the actual text shown)
125
+ # 2. The target of the hyperlink (e.g. https://google.com)
126
+ # 3. The text which will be displayed if you hover over the link
127
+ def hyperlink(desc, target, hover)
128
+ text('[' + desc + ']' + '(' + target + ' ' + '"' + hover + '"' + ')')
129
+ end
130
+
131
+ # Adds an image.
132
+ #
133
+ # This method takes three arguments:
134
+ # 1. The alternative text displayed if no image could be loaded
135
+ # 2. The path/resource of the image (e.g on your file system)
136
+ # 3. The text which will be displayed if you hover over the image
137
+ def image(alternative, path, hover)
138
+ text('![' + alternative + ']' + '(' + path + ' ' + '"' + hover + '"' + ')')
139
+ end
140
+
141
+ # Adds a new (empty) line.
142
+ def new_line
143
+ two_spaces = ' '
144
+ text(two_spaces + line_feed)
145
+ end
146
+
147
+ # Adds a new paragraph.
148
+ def paragraph
149
+ text(line_feed + line_feed)
150
+ end
151
+
152
+ # Converts this object to a string.
153
+ #
154
+ # In other words this method should be the final call you should invoke when
155
+ # you done creating the markdown content. After this call you can use the
156
+ # produced string and show it in a markdown viewer for example.
157
+ def to_s
158
+ @md
159
+ end
160
+
161
+ private
162
+
163
+ def line_feed
164
+ "\n"
165
+ end
166
+ end
@@ -0,0 +1,28 @@
1
+ # MIT License
2
+ #
3
+ # Copyright 2019 Niklas Schultz.
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ # author:: Niklas Schultz
24
+ # version:: 0.1.0
25
+ # license:: MII
26
+ module FluentMarkdownBuilder
27
+ VERSION = '0.1.0'
28
+ end
@@ -0,0 +1,28 @@
1
+ # MIT License
2
+ #
3
+ # Copyright 2019 Niklas Schultz.
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+
24
+ # author:: Niklas Schultz
25
+ # version:: 0.1.0
26
+ # license:: MII
27
+ require 'core/version'
28
+ require 'core/markdown.rb'
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent_markdown_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Niklas Schultz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-26 00:00:00.000000000 Z
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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '5.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.10'
55
+ description: A fluent interface to generate markdown easily.
56
+ email:
57
+ - thexsalkin@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - fluent_markdown_builder.gemspec
70
+ - lib/core/markdown.rb
71
+ - lib/core/version.rb
72
+ - lib/fluent_markdown_builder.rb
73
+ homepage: https://github.com/SNException/fluent_markdown_builder
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.7.6
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: A fluent markdown builder
97
+ test_files: []