Module: Refs
- Defined in:
- lib/refs.rb,
lib/refs/refs.rb
Constant Summary collapse
- VERSION =
"1.1.0"
- REF_DIR =
"#{ENV['HOME']}/.refs/"
Class Method Summary collapse
Class Method Details
.access_ref(ref) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/refs/refs.rb', line 4 def self.access_ref(ref) if !Dir.exists?(REF_DIR) Dir.mkdir(REF_DIR) end Dir.chdir(REF_DIR) the_ref = ref.dup the_ref.strip! if File.exists?("#{the_ref}.md") file_content = "" File.open("#{the_ref}.md", 'r') do |f| f.each_line do |line| file_content << line end end doc = Maruku.new(file_content) html_contents = doc.to_html_document File.open("#{the_ref}.html", 'w') do |f| f.write html_contents Launchy::Browser.run(File.absolute_path(f)) end else if File.exists?("style.css") File.open("#{the_ref}.md", 'w') do |f| f.write('<link rel="stylesheet" href="style.css" />') end end system("#{ENV['EDITOR']} \"#{the_ref}.md\"") exit 0 end end |
.delete_ref(ref) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/refs/refs.rb', line 52 def self.delete_ref(ref) Dir.chdir(REF_DIR) if File.exists?("#{ref}.md") File.delete("#{ref}.md") if File.exists?("#{ref}.html") File.delete("#{ref}.html") end puts "Deleted #{ref}" else puts "Error, the reference you're trying to delete doesn't exist." exit 1 end end |
.edit_ref(ref) ⇒ Object
47 48 49 50 |
# File 'lib/refs/refs.rb', line 47 def self.edit_ref(ref) Dir.chdir(REF_DIR) system("#{ENV['EDITOR']} \"#{ref}.md\"") end |
.list ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/refs/refs.rb', line 39 def self.list Dir.chdir(REF_DIR) Dir.foreach(".") do |f| next if f == ".." or f =="." f.match(/(?<ref-name>.+)\.md/) { |m| puts m['ref-name'] } end end |