mdrb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +15 -0
- data/LICENSE +21 -0
- data/README.md +75 -0
- data/lib/mdrb.rb +196 -0
- data/lib/mdrb/post_message.rb +17 -0
- data/lib/mdrb/version.rb +3 -0
- data/mdrb.gemspec +25 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fda49f4b294226a5d59ede6ba7f9c5c6c46c4f3af243487a6a152de9d5102d1e
|
4
|
+
data.tar.gz: 69f751859740f7f5dd750d8d58428fd033adfb40b72db408397c8732e9600fcd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eefa4e54274d628f54fee3f4a220df94b8333bd26b6f6247d12ddff6f0553b1372aeffed5ca90dfafc90d6ddde7303b3079edce6f276391cddedd28560532f8a
|
7
|
+
data.tar.gz: 6b8b96c11c4ac08db60150b7321e83d2e71041df2e0ba4e0536c0990f3e61337f703fab54b894cf77bbb9e4e4550182c5a26ff713d8df79ce381fa251f96fd1b
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
Just be nice.
|
4
|
+
|
5
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
6
|
+
|
7
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
8
|
+
|
9
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
10
|
+
|
11
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
12
|
+
|
13
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
14
|
+
|
15
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Bryan Lim
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# md.rb
|
2
|
+
|
3
|
+
Create and manage multiple markdown documents easily.
|
4
|
+
|
5
|
+
Some of the key features are:
|
6
|
+
|
7
|
+
0. Having a simple syntax and api
|
8
|
+
1. Generate, read, update and delete multiple markdown
|
9
|
+
2. Get json from markdown
|
10
|
+
|
11
|
+
# Install
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install mdrb
|
15
|
+
```
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'mdrb'
|
19
|
+
```
|
20
|
+
|
21
|
+
# usage
|
22
|
+
|
23
|
+
Create markdown
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
MD.create("first", "# Hello") #first.md
|
27
|
+
MD.create("first document", "# Hello") #first-document.md
|
28
|
+
```
|
29
|
+
|
30
|
+
Create multiple markdown
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
MD.create_many(["first","second"], ["# first","# second"]) #first.md second.md
|
34
|
+
|
35
|
+
MD.create_many(["first document","second document"], ["# first","# second"]) #first-document.md second.md
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
Get json from markdown
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
MD.create("first", "# first")
|
43
|
+
puts json = MD.to_json("first")
|
44
|
+
```
|
45
|
+
|
46
|
+
Update markdown
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
MD.update(path, content)
|
50
|
+
MD.update_on(which_line, path, content)
|
51
|
+
MD.update_many()
|
52
|
+
```
|
53
|
+
|
54
|
+
Delete markdown
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
MD.create_many(["first","second"], ["# first", "# second"])
|
58
|
+
MD.delete("first")
|
59
|
+
MD.delete_many(["first", "second"])
|
60
|
+
```
|
61
|
+
|
62
|
+
Read markdown
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
MD.read()
|
66
|
+
MD.read_many()
|
67
|
+
```
|
68
|
+
|
69
|
+
# Testing
|
70
|
+
|
71
|
+
rspec
|
72
|
+
|
73
|
+
# license
|
74
|
+
|
75
|
+
MIT | ytbryan@hey.com
|
data/lib/mdrb.rb
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module MD
|
4
|
+
|
5
|
+
#checking the syntax of the markdown
|
6
|
+
# return true or false
|
7
|
+
def self.check(path_to_syntax)
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
# MD.exist? is like File.exist?
|
12
|
+
# May include better error next time
|
13
|
+
def self.exist?(path)
|
14
|
+
return true if existence?(path)
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.create(path, content)
|
19
|
+
touch(path)
|
20
|
+
write(path, content)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.create_many(path_array, content_array)
|
24
|
+
return MDError("Different in the length of arrays") if difference_in_length?(path_array, content_array)
|
25
|
+
path_array.each {|each_path|
|
26
|
+
touch(each_path)
|
27
|
+
}
|
28
|
+
|
29
|
+
content_array.each_with_index {|each_content, index|
|
30
|
+
write(path_array[index], each_content)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# This is read but return it
|
35
|
+
# as a json file
|
36
|
+
def self.to_json(path)
|
37
|
+
array = File.readlines(marked_down(path))
|
38
|
+
answer = []
|
39
|
+
array.each_with_index { |item, i|
|
40
|
+
answer.push(i)
|
41
|
+
answer.push(item)
|
42
|
+
}
|
43
|
+
return Hash[*answer].to_json
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.to_json_many(path_array)
|
47
|
+
answer = []
|
48
|
+
path_array.each {|path|
|
49
|
+
answer.push(to_json(path))
|
50
|
+
}
|
51
|
+
answer
|
52
|
+
end
|
53
|
+
|
54
|
+
# read the file
|
55
|
+
def self.read(path)
|
56
|
+
File.read(marked_down(path))
|
57
|
+
end
|
58
|
+
|
59
|
+
#read many markdown
|
60
|
+
def self.read_many(path_array)
|
61
|
+
answer = []
|
62
|
+
path_array.each {|path|
|
63
|
+
answer.push(File.readlines(marked_down(path)))
|
64
|
+
}
|
65
|
+
answer
|
66
|
+
end
|
67
|
+
|
68
|
+
# move the file
|
69
|
+
def self.move(path, newpath)
|
70
|
+
FileUtils.mv(marked_down(path), marked_down(newpath))
|
71
|
+
end
|
72
|
+
|
73
|
+
#move many of the file
|
74
|
+
def self.move_many(path_array, new_path_array)
|
75
|
+
return MDError("Different in size") if path_array.length != new_path_array.length
|
76
|
+
new_path_array.each_with_index { |each_new_p, i|
|
77
|
+
move(path_array[i], each_new_p)
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
# remove the file
|
82
|
+
def self.delete(path)
|
83
|
+
File.delete(marked_down(path))
|
84
|
+
end
|
85
|
+
|
86
|
+
# delete many markdown
|
87
|
+
def self.delete_many(path_array)
|
88
|
+
path_array.each {|path|
|
89
|
+
File.delete(marked_down(path))
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
# update the markdown
|
94
|
+
def self.update(path, content)
|
95
|
+
return MDError("File too big") if file_too_big?(path) == true
|
96
|
+
move(path, path+".draft")
|
97
|
+
create(path, content) #create
|
98
|
+
delete(path+".draft") #delete
|
99
|
+
end
|
100
|
+
|
101
|
+
# update many markdown
|
102
|
+
def self.update_many(path_array, content_array)
|
103
|
+
return MDError("Different in the length of arrays") if difference_in_length?(path_array, content_array)
|
104
|
+
content_array.each_with_index { |each_content, i|
|
105
|
+
update(path_array[i], each_content)
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
# append to the markdown file
|
110
|
+
def self.append(path, content)
|
111
|
+
add(path, content)
|
112
|
+
end
|
113
|
+
|
114
|
+
# append many markdown
|
115
|
+
def self.append_many(path_array, content_array)
|
116
|
+
content_array.each_with_index {|each_content, i|
|
117
|
+
add(path_array[i], each_content)
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
# update on the single line
|
122
|
+
def self.update_on(which_line, path, content)
|
123
|
+
return MDError("File too big") if file_too_big?(path)
|
124
|
+
array = File.readlines(path)
|
125
|
+
end
|
126
|
+
|
127
|
+
# read the line of markdown
|
128
|
+
def self.read_line(which_line, path_to_file)
|
129
|
+
return MDError("File too big") if file_too_big?(path)
|
130
|
+
array = File.readlines(path)
|
131
|
+
array[which_line] if array != nil && array.length >= which_line
|
132
|
+
end
|
133
|
+
|
134
|
+
# list all the markdown files in the
|
135
|
+
# directory
|
136
|
+
def self.list(path)
|
137
|
+
tasks_array = Dir.entries(path).sort_by { |x| File.birthtime(path + x) }
|
138
|
+
|
139
|
+
return tasks_array.reject {|f|
|
140
|
+
f[0].include?('.') || is_md_extension? == true
|
141
|
+
}.collect {|x| (path + x)}
|
142
|
+
end
|
143
|
+
|
144
|
+
private #=================================================
|
145
|
+
|
146
|
+
def self.existence?(path)
|
147
|
+
File.exist?(marked_down(path)) == true
|
148
|
+
end
|
149
|
+
|
150
|
+
# TODO check if the file is too big\
|
151
|
+
def self.file_too_big?(path)
|
152
|
+
false
|
153
|
+
end
|
154
|
+
|
155
|
+
# Bryan, you can do better with the naming of marked_down
|
156
|
+
# always produce a path that has .md
|
157
|
+
def self.marked_down(path)
|
158
|
+
if is_md_extension?(path.dash)
|
159
|
+
path
|
160
|
+
else
|
161
|
+
path + ".md"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.difference_in_length?(path_array, content_array)
|
166
|
+
path_array.length != content_array.length
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.add(path,content)
|
170
|
+
File.write(marked_down(path.dash), content, mode: "a")
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.write(path, content)
|
174
|
+
File.write(marked_down(path.dash), content, mode: "w")
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.touch(path)
|
178
|
+
FileUtils.touch(marked_down(path.dash))
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.is_md_extension?(path)
|
182
|
+
path[path.length-3..path.length] == ".md"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
module MDError
|
187
|
+
def initialize(str)
|
188
|
+
puts str
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
class String
|
193
|
+
def dash
|
194
|
+
self.gsub(" ", "-").strip
|
195
|
+
end
|
196
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MD
|
2
|
+
MESSAGE = "
|
3
|
+
|
4
|
+
███╗ ███╗██████╗ ██████╗ ██████╗
|
5
|
+
████╗ ████║██╔══██╗██╔══██╗██╔══██╗
|
6
|
+
██╔████╔██║██║ ██║██████╔╝██████╔╝
|
7
|
+
██║╚██╔╝██║██║ ██║██╔══██╗██╔══██╗
|
8
|
+
██║ ╚═╝ ██║██████╔╝██║ ██║██████╔╝
|
9
|
+
╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═════╝
|
10
|
+
|
11
|
+
###############################
|
12
|
+
|
13
|
+
Full Changelog -> https://github.com/ytbryan/mdrb/blob/master/changelog.md
|
14
|
+
|
15
|
+
Pull Request -> https://github.com/ytbryan/mdrb/pulls
|
16
|
+
"
|
17
|
+
end
|
data/lib/mdrb/version.rb
ADDED
data/mdrb.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mdrb/version'
|
5
|
+
require 'mdrb/post_message'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "mdrb"
|
9
|
+
spec.version = MD::VERSION
|
10
|
+
spec.authors = ["Bryan Lim"]
|
11
|
+
spec.email = ["ytbryan@hey.com"]
|
12
|
+
spec.summary = %q{Create and manage markdown}
|
13
|
+
spec.description = %q{ Create and manage markdown}
|
14
|
+
spec.homepage = "https://github.com/ytbryan/mdrb"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
spec.post_install_message = MD::MESSAGE
|
19
|
+
spec.required_ruby_version = ">= 2.0.0"
|
20
|
+
spec.add_dependency 'file-utils' , '~> 0.1.0'
|
21
|
+
spec.add_development_dependency "rspec", "~> 3.9.0"
|
22
|
+
# spec.add_dependency 'thor' , '~> 0.19.4'
|
23
|
+
# spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
# spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mdrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryan Lim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: file-utils
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.9.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.9.0
|
41
|
+
description: " Create and manage markdown"
|
42
|
+
email:
|
43
|
+
- ytbryan@hey.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- lib/mdrb.rb
|
54
|
+
- lib/mdrb/post_message.rb
|
55
|
+
- lib/mdrb/version.rb
|
56
|
+
- mdrb.gemspec
|
57
|
+
homepage: https://github.com/ytbryan/mdrb
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message: "\n\n███╗ ███╗██████╗ ██████╗ ██████╗\n████╗ ████║██╔══██╗██╔══██╗██╔══██╗\n██╔████╔██║██║
|
62
|
+
\ ██║██████╔╝██████╔╝\n██║╚██╔╝██║██║ ██║██╔══██╗██╔══██╗\n██║ ╚═╝ ██║██████╔╝██║
|
63
|
+
\ ██║██████╔╝\n╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═════╝\n\n ###############################\n\n
|
64
|
+
\ Full Changelog -> https://github.com/ytbryan/mdrb/blob/master/changelog.md\n\n
|
65
|
+
\ Pull Request -> https://github.com/ytbryan/mdrb/pulls\n "
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 2.0.0
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.0.3
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Create and manage markdown
|
84
|
+
test_files: []
|