johnny 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
File without changes
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/johnny ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "johnny"))
4
+
5
+ Johnny.new.run!
data/lib/johnny.rb ADDED
@@ -0,0 +1,89 @@
1
+ require "rubygems"
2
+ require "erb"
3
+ require "fssm"
4
+ require "rdiscount"
5
+
6
+ class Johnny
7
+ def initialize(dir=Dir.pwd)
8
+ @source = File.expand_path(dir)
9
+ @destination = File.join(@source, "html")
10
+
11
+ @template = ERB.new(File.read(File.expand_path(File.join(File.dirname(__FILE__), "..", "templates", "default.html.erb"))))
12
+
13
+ unless File.exists?(@destination) && File.directory?(@destination)
14
+ Dir.mkdir(@destination)
15
+ end
16
+ end
17
+
18
+ def handle(action, path)
19
+ if [".md", ".mdown", ".markdown"].include?(File.extname(path))
20
+ source = File.join(@source, path)
21
+ target = File.join(@destination, "#{File.basename(path, File.extname(path))}.html")
22
+ action = "handle_#{action}"
23
+
24
+ if self.respond_to?(action)
25
+ self.send(action, source, target)
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+ def handle_create(source, target)
32
+ parse(source, target)
33
+ puts "Create: #{target}"
34
+
35
+ return true
36
+ end
37
+
38
+ def handle_update(source, target)
39
+ parse(source, target)
40
+ puts "Update: #{target}"
41
+
42
+ return true
43
+ end
44
+
45
+ def handle_delete(source, target)
46
+ if File.exists?(target)
47
+ puts "Deleted: #{target}"
48
+ File.delete(target)
49
+ end
50
+ end
51
+
52
+ def run!
53
+ # this is something I'd expect in javascript, not ruby.
54
+ johnny = self
55
+
56
+ puts "Watching directory for changes to files..."
57
+ puts "-> Parsed files will be placed in: #{File.join(Dir.pwd, "html")}"
58
+
59
+ FSSM.monitor(@source, "**/*.*") do
60
+ update {|base, relative| johnny.handle("update", relative) }
61
+ delete {|base, relative| johnny.handle("delete", relative) }
62
+ create {|base, relative| johnny.handle("create", relative) }
63
+ end
64
+
65
+ return
66
+ end
67
+
68
+ def parse(source, target)
69
+ File.open("#{target}", "w+") {|f|
70
+ f.write(@template.result(ERBTemplate.new(
71
+ File.basename(source, File.extname(source)),
72
+ RDiscount.new(File.read(source)).to_html
73
+ ).getBinding))
74
+ }
75
+
76
+ return nil
77
+ end
78
+ end
79
+
80
+ class ERBTemplate
81
+ def initialize(title, content)
82
+ @title = title
83
+ @content = content
84
+ end
85
+
86
+ def getBinding
87
+ return binding()
88
+ end
89
+ end
@@ -0,0 +1,60 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
+ "http://www.w3.org/TR/html4/loose.dtd">
3
+
4
+ <html lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7
+ <title><%= @title %></title>
8
+ <style type='text/css'>
9
+ body {margin:0}
10
+ #wrapper, #wrapper code, #wrapper pre, #wrapper tt, #wrapper kbd, #wrapper samp {
11
+ font-family:serif;
12
+ font-size:15px;
13
+ line-height:1.3;
14
+ color:#343331;
15
+ background:#fff; }
16
+ #wrapper { max-width:89ex; text-align:justify; margin:0 25px 25px 25px }
17
+ #wrapper h1, #wrapper h2, #wrapper h3 { color:#232221;clear:left }
18
+ #wrapper h1 { font-size:28px; margin:15px 0 30px 0; text-align:center }
19
+ #wrapper h2 { font-size:18px; margin-bottom:0; margin-top:10px; line-height:1.3; }
20
+ #wrapper h3 { font-size:16px; margin:0 0 0 4ex; }
21
+ #wrapper p, #wrapper ul, #wrapper ol, #wrapper dl, #wrapper pre { margin:0 0 18px 0; }
22
+ #wrapper pre {
23
+ color:#333231;
24
+ background:#edeceb;
25
+ padding:5px 7px;
26
+ margin:0px 0 20px 0;
27
+ border-left:2ex solid #ddd}
28
+ #wrapper pre + h2, #wrapper pre + h3 {
29
+ margin-top:22px;
30
+ }
31
+ #wrapper h2 + pre, #wrapper h3 + pre {
32
+ margin-top:5px;
33
+ }
34
+ #wrapper > p, #wrapper > ul, #wrapper > ol, #wrapper > dl, #wrapper > pre { margin-left:8ex; }
35
+ #wrapper dt { margin:0; clear:left }
36
+ #wrapper dt.flush { float:left; width:8ex }
37
+ #wrapper dd { margin:0 0 0 9ex }
38
+ #wrapper code, #wrapper strong, #wrapper b { font-weight:bold; color:#131211; }
39
+ #wrapper pre code { font-weight:normal; color:#232221; background:inherit }
40
+ #wrapper em, var, u {
41
+ font-style:normal; color:#333231; border-bottom:1px solid #999; }
42
+ #wrapper h1.wrapper-title { display:none; }
43
+ #wrapper ol.wrapper, #wrapper ol.wrapper li { margin:2px 0 10px 0; padding:0;
44
+ float:left; width:33%; list-style-type:none;
45
+ text-transform:uppercase; font-size:18px; color:#999;
46
+ letter-spacing:1px;}
47
+ #wrapper ol.wrapper { width:100%; }
48
+ #wrapper ol.wrapper li.tl { text-align:left }
49
+ #wrapper ol.wrapper li.tc { text-align:center;letter-spacing:4px }
50
+ #wrapper ol.wrapper li.tr { text-align:right }
51
+ #wrapper ol.wrapper a { color:#999 }
52
+ #wrapper ol.wrapper a:hover { color:#333231 }
53
+ </style>
54
+ </head>
55
+ <body>
56
+ <div id="wrapper">
57
+ <%= @content %>
58
+ </div>
59
+ </body>
60
+ </html>
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: johnny
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Micheil Smith
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-29 00:00:00 +11:00
18
+ default_executable: johnny
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: fssm
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: rdiscount
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ description: Watches directories and converts markdown documents to other formats through erb templates
45
+ email: micheil@brandedcode.com
46
+ executables:
47
+ - johnny
48
+ extensions: []
49
+
50
+ extra_rdoc_files:
51
+ - README.md
52
+ files:
53
+ - README.md
54
+ - VERSION
55
+ - bin/johnny
56
+ - lib/johnny.rb
57
+ - templates/default.html.erb
58
+ has_rdoc: true
59
+ homepage: http://github.com/miksago/johnny
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.6
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Watches directories and converts markdown documents to other formats
88
+ test_files: []
89
+