Module: MD
- Defined in:
- lib/mdrb.rb,
lib/mdrb/version.rb,
lib/mdrb/post_message.rb
Constant Summary collapse
- VERSION =
"0.0.2"
- MESSAGE =
" ███╗ ███╗██████╗ ██████╗ ██████╗ ████╗ ████║██╔══██╗██╔══██╗██╔══██╗ ██╔████╔██║██║ ██║██████╔╝██████╔╝ ██║╚██╔╝██║██║ ██║██╔══██╗██╔══██╗ ██║ ╚═╝ ██║██████╔╝██║ ██║██████╔╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═════╝ ############################### Full Changelog -> https://github.com/ytbryan/mdrb/blob/master/changelog.md Pull Request -> https://github.com/ytbryan/mdrb/pulls "
Class Method Summary collapse
-
.append(path, content) ⇒ Object
append to the markdown file.
-
.append_many(path_array, content_array) ⇒ Object
append many markdown.
-
.check(path_to_syntax) ⇒ Object
checking the syntax of the markdown return true or false.
- .create(path, content) ⇒ Object
- .create_many(path_array, content_array) ⇒ Object
-
.delete(path) ⇒ Object
remove the file.
-
.delete_many(path_array) ⇒ Object
delete many markdown.
-
.exist?(path) ⇒ Boolean
MD.exist? is like File.exist? May include better error next time.
-
.list(path) ⇒ Object
list all the markdown files in the directory.
-
.move(path, newpath) ⇒ Object
move the file.
-
.move_many(path_array, new_path_array) ⇒ Object
move many of the file.
-
.read(path) ⇒ Object
read the file.
-
.read_line(which_line, path_to_file) ⇒ Object
read the line of markdown.
-
.read_many(path_array) ⇒ Object
read many markdown.
-
.to_json(path) ⇒ Object
This is read but return it as a json file.
- .to_json_many(path_array) ⇒ Object
-
.update(path, content) ⇒ Object
update the markdown.
-
.update_many(path_array, content_array) ⇒ Object
update many markdown.
-
.update_on(which_line, path, content) ⇒ Object
update on the single line.
Class Method Details
.append(path, content) ⇒ Object
append to the markdown file
110 111 112 |
# File 'lib/mdrb.rb', line 110 def self.append(path, content) add(path, content) end |
.append_many(path_array, content_array) ⇒ Object
append many markdown
115 116 117 118 119 |
# File 'lib/mdrb.rb', line 115 def self.append_many(path_array, content_array) content_array.each_with_index {|each_content, i| add(path_array[i], each_content) } end |
.check(path_to_syntax) ⇒ Object
checking the syntax of the markdown return true or false
7 8 9 |
# File 'lib/mdrb.rb', line 7 def self.check(path_to_syntax) end |
.create(path, content) ⇒ Object
18 19 20 21 |
# File 'lib/mdrb.rb', line 18 def self.create(path, content) touch(path) write(path, content) end |
.create_many(path_array, content_array) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mdrb.rb', line 23 def self.create_many(path_array, content_array) return MDError("Different in the length of arrays") if difference_in_length?(path_array, content_array) path_array.each {|each_path| touch(each_path) } content_array.each_with_index {|each_content, index| write(path_array[index], each_content) } end |
.delete(path) ⇒ Object
remove the file
82 83 84 |
# File 'lib/mdrb.rb', line 82 def self.delete(path) File.delete(marked_down(path)) end |
.delete_many(path_array) ⇒ Object
delete many markdown
87 88 89 90 91 |
# File 'lib/mdrb.rb', line 87 def self.delete_many(path_array) path_array.each {|path| File.delete(marked_down(path)) } end |
.exist?(path) ⇒ Boolean
MD.exist? is like File.exist? May include better error next time
13 14 15 16 |
# File 'lib/mdrb.rb', line 13 def self.exist?(path) return true if existence?(path) false end |
.list(path) ⇒ Object
list all the markdown files in the directory
136 137 138 139 140 141 142 |
# File 'lib/mdrb.rb', line 136 def self.list(path) tasks_array = Dir.entries(path).sort_by { |x| File.birthtime(path + x) } return tasks_array.reject {|f| f[0].include?('.') || is_md_extension? == true }.collect {|x| (path + x)} end |
.move(path, newpath) ⇒ Object
move the file
69 70 71 |
# File 'lib/mdrb.rb', line 69 def self.move(path, newpath) FileUtils.mv(marked_down(path), marked_down(newpath)) end |
.move_many(path_array, new_path_array) ⇒ Object
move many of the file
74 75 76 77 78 79 |
# File 'lib/mdrb.rb', line 74 def self.move_many(path_array, new_path_array) return MDError("Different in size") if path_array.length != new_path_array.length new_path_array.each_with_index { |each_new_p, i| move(path_array[i], each_new_p) } end |
.read(path) ⇒ Object
read the file
55 56 57 |
# File 'lib/mdrb.rb', line 55 def self.read(path) File.read(marked_down(path)) end |
.read_line(which_line, path_to_file) ⇒ Object
read the line of markdown
128 129 130 131 132 |
# File 'lib/mdrb.rb', line 128 def self.read_line(which_line, path_to_file) return MDError("File too big") if file_too_big?(path) array = File.readlines(path) array[which_line] if array != nil && array.length >= which_line end |
.read_many(path_array) ⇒ Object
read many markdown
60 61 62 63 64 65 66 |
# File 'lib/mdrb.rb', line 60 def self.read_many(path_array) answer = [] path_array.each {|path| answer.push(File.readlines(marked_down(path))) } answer end |
.to_json(path) ⇒ Object
This is read but return it as a json file
36 37 38 39 40 41 42 43 44 |
# File 'lib/mdrb.rb', line 36 def self.to_json(path) array = File.readlines(marked_down(path)) answer = [] array.each_with_index { |item, i| answer.push(i) answer.push(item) } return Hash[*answer].to_json end |
.to_json_many(path_array) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/mdrb.rb', line 46 def self.to_json_many(path_array) answer = [] path_array.each {|path| answer.push(to_json(path)) } answer end |
.update(path, content) ⇒ Object
update the markdown
94 95 96 97 98 99 |
# File 'lib/mdrb.rb', line 94 def self.update(path, content) return MDError("File too big") if file_too_big?(path) == true move(path, path+".draft") create(path, content) #create delete(path+".draft") #delete end |
.update_many(path_array, content_array) ⇒ Object
update many markdown
102 103 104 105 106 107 |
# File 'lib/mdrb.rb', line 102 def self.update_many(path_array, content_array) return MDError("Different in the length of arrays") if difference_in_length?(path_array, content_array) content_array.each_with_index { |each_content, i| update(path_array[i], each_content) } end |
.update_on(which_line, path, content) ⇒ Object
update on the single line
122 123 124 125 |
# File 'lib/mdrb.rb', line 122 def self.update_on(which_line, path, content) return MDError("File too big") if file_too_big?(path) array = File.readlines(path) end |