chopin 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/chopin +6 -0
- data/lib/chopin.rb +91 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6739de2070eba6ab1314d0ffcd687d779c92f1f0
|
4
|
+
data.tar.gz: 608de643852b5f928c0c174ab14b41b27be1f142
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d74357443a30c6f6b930921853bf6feb1c70525b38a76f43ab2c7ffa462053fe4d229323fd7ccd53fd06752107f9b6bf8d3a744c29f6ca737bcdb5f29bf53ea
|
7
|
+
data.tar.gz: fc6518a2b9a3d57e15cf9298ce5dc0e662520b20d451e43fc64554173ad2e79c9009a230aaa485eea2b802af6ba94014a3aa6c1fb777a42bc2959cae1cf04509
|
data/bin/chopin
ADDED
data/lib/chopin.rb
CHANGED
@@ -1,5 +1,94 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'redcarpet'
|
4
|
+
|
5
|
+
BLUE = "\033[0;34m"
|
6
|
+
GREEN = "\033[0;32m"
|
7
|
+
GRAY = "\033[1;30m"
|
8
|
+
PURPLE = "\033[0;35m"
|
9
|
+
WHITE = "\033[0m"
|
10
|
+
|
1
11
|
class Chopin
|
2
|
-
def
|
3
|
-
|
12
|
+
def initialize(src_path = nil, dest_path = nil)
|
13
|
+
Dir.mkdir(dest_path) unless Dir.exist?(dest_path) || File.exist?(dest_path)
|
14
|
+
|
15
|
+
@src_path = File.realpath(src_path.nil? ? '.' : src_path)
|
16
|
+
@dest_path = File.realpath(dest_path.nil? ? '.dist' : dest_path)
|
17
|
+
@markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new)
|
18
|
+
|
19
|
+
puts "Source : #{@src_path}"
|
20
|
+
puts "Destination : #{@dest_path}"
|
21
|
+
puts
|
22
|
+
end
|
23
|
+
|
24
|
+
def build(src_path = @src_path, dest_path = @dest_path, layout = nil)
|
25
|
+
puts "File #{dest_path} exists" if File.exist?(dest_path)
|
26
|
+
puts "Directory #{dest_path} exists" if Dir.exist?(dest_path)
|
27
|
+
Dir.mkdir(dest_path) unless Dir.exist?(dest_path)
|
28
|
+
|
29
|
+
src_dir = Dir.new(src_path)
|
30
|
+
dest_dir = Dir.new(dest_path)
|
31
|
+
|
32
|
+
if File.exist?("#{src_path}/layout.erb")
|
33
|
+
layout = "#{src_path}/layout.erb"
|
34
|
+
end
|
35
|
+
|
36
|
+
sub_directories = []
|
37
|
+
|
38
|
+
src_dir.each do |entry|
|
39
|
+
next if entry[0] == '.'
|
40
|
+
|
41
|
+
source = "#{src_path}/#{entry}"
|
42
|
+
destination = "#{dest_path}/#{entry}"
|
43
|
+
|
44
|
+
if File.directory?(source)
|
45
|
+
sub_directories << [source, destination]
|
46
|
+
else
|
47
|
+
case File.extname(entry)
|
48
|
+
when '.erb'
|
49
|
+
unless entry == 'layout.erb'
|
50
|
+
process_erb(source, layout, destination.sub('.erb', '.html'))
|
51
|
+
end
|
52
|
+
when '.md'
|
53
|
+
process_markdown(source, layout, destination.sub('.md', '.html'))
|
54
|
+
else
|
55
|
+
copy_file(source, destination)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
sub_directories.each do |source, destination|
|
61
|
+
build(source, destination, layout)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def copy_file(source, destination)
|
66
|
+
print " #{rel_src_path source} => "
|
67
|
+
FileUtils.cp(source, destination)
|
68
|
+
puts " #{GREEN}#{rel_dest_path destination}#{WHITE}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def process_erb(source, layout, destination)
|
72
|
+
print " #{rel_src_path source} [#{rel_src_path File.realpath(layout)}] => "
|
73
|
+
render = Proc.new { ERB.new(File.read(source)).result }
|
74
|
+
output = ERB.new(File.read(layout)).result(nil, &render)
|
75
|
+
File.new(destination, 'w').write(output)
|
76
|
+
puts "#{GREEN}#{rel_dest_path destination}#{WHITE}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def process_markdown(source, layout, destination)
|
80
|
+
print " #{rel_src_path source} [#{rel_src_path File.realpath(layout)}] => "
|
81
|
+
render = Proc.new { @markdown.render(File.new(source).read) }
|
82
|
+
output = ERB.new(File.read(layout)).result(nil, &render)
|
83
|
+
File.new(destination, 'w').write(output)
|
84
|
+
puts "#{GREEN}#{rel_dest_path destination}#{WHITE}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def rel_dest_path(path)
|
88
|
+
path.sub("#{@dest_path}/", '')
|
89
|
+
end
|
90
|
+
|
91
|
+
def rel_src_path(path)
|
92
|
+
path.sub("#{@src_path}/", '')
|
4
93
|
end
|
5
94
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chopin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Forisha
|
@@ -12,10 +12,12 @@ date: 2015-03-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
13
13
|
description: A simple static site generator
|
14
14
|
email: josh@forisha.com
|
15
|
-
executables:
|
15
|
+
executables:
|
16
|
+
- chopin
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
20
|
+
- bin/chopin
|
19
21
|
- lib/chopin.rb
|
20
22
|
homepage: https://github.com/joshforisha/chopin
|
21
23
|
licenses:
|