mdnotes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/mdnotes +4 -0
  2. data/lib/mdnotes.rb +107 -0
  3. metadata +48 -0
data/bin/mdnotes ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mdnotes'
4
+ MDNotes.new.start
data/lib/mdnotes.rb ADDED
@@ -0,0 +1,107 @@
1
+ require 'rdiscount'
2
+ class MDNotes
3
+ # Params
4
+
5
+ def initialize
6
+ @first_setup = false
7
+ @notes = Dir['./md/*.md']
8
+ @pwd = Dir::pwd;
9
+ @publishing = false
10
+
11
+ @params = {}
12
+
13
+ # Set the params
14
+ ARGV.each do |arg|
15
+ cur_arg = arg.tr "-", ""
16
+ @params[cur_arg] = true
17
+ end
18
+ end
19
+
20
+ # Check if directory is ready
21
+
22
+ def check_directories
23
+ missing_dirs = {}
24
+
25
+ ['pdf','html', 'md', 'html/images'].each do |f|
26
+ cur_dir = "./" + f
27
+ curr_dir_exists = FileTest::directory?(cur_dir)
28
+ missing_dirs[f] = curr_dir_exists
29
+ @first_setup ||= curr_dir_exists
30
+ end
31
+
32
+ # Make the name meaningful
33
+ @first_setup = !@first_setup
34
+
35
+ if @first_setup
36
+ puts "Detecting first time setup..."
37
+ end
38
+
39
+ # Create the mssign directories
40
+ create_directories missing_dirs
41
+ end
42
+
43
+ def create_directories dirs
44
+ dirs.each_pair do |k,v|
45
+
46
+ cur_dir = @pwd + "/" + k
47
+
48
+ if (!v)
49
+ Dir::mkdir(cur_dir)
50
+ puts "Creating directory #{k}..."
51
+ end
52
+ end
53
+ end
54
+
55
+
56
+
57
+
58
+ def compile_notes
59
+ if !@first_setup
60
+ @notes.each do |n|
61
+ name = n.split('/')[-1].split('.')[0]
62
+
63
+ puts "Compiling #{name}..."
64
+
65
+ raw = open(n).read
66
+ md = RDiscount.new raw
67
+ out = md.to_html
68
+ open("./html/#{name}.html", "w").write out
69
+ end
70
+
71
+ end
72
+ puts "Notes compiled."
73
+ end
74
+
75
+
76
+ def publish_notes
77
+ publishing = (@params['p'] || @params['publish']) && (require 'pdfkit')
78
+
79
+ if publishing
80
+ pdf_home = "./pdf"
81
+ Dir::mkdir(pdf_home) unless FileTest::directory?(pdf_home)
82
+
83
+ Dir["./html/*.html"].each do |html|
84
+ f_name = html.split("/")[-1].split(".")[0]
85
+
86
+ html_file = open(html).read
87
+
88
+ puts "Publishing #{f_name}..."
89
+ kit = PDFKit.new(html_file, :page_size => 'Letter')
90
+ kit.to_file( File.join(".", "pdf", f_name + ".pdf"))
91
+ end
92
+ puts "Notes published."
93
+ end
94
+
95
+ end
96
+
97
+ end
98
+
99
+
100
+ def start
101
+ check_directories
102
+ compile_notes
103
+ publish_notes
104
+ end
105
+
106
+
107
+
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdnotes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Uri Gorelik
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-26 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Suite for taking easy notes in markdown and then converting to html and
15
+ pdf.
16
+ email: uri.gore@gmail.com
17
+ executables:
18
+ - mdnotes
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/mdnotes.rb
23
+ - bin/mdnotes
24
+ homepage: http://rubygems.org/gems/example
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.10
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: Suite for taking easy notes in markdown and then converting to html and pdf.
48
+ test_files: []