chopin 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60b1db1e93ceb04f686960f4efbad2c9db78fbc2
4
- data.tar.gz: 290a391e00041e474cadd99d3ad865562c15a8a3
3
+ metadata.gz: fd51bfb52c9d11bb639c229efbfd73ade846d6ad
4
+ data.tar.gz: 8c0962eb4754366391bc933c02d13b8a1dc01303
5
5
  SHA512:
6
- metadata.gz: 7d75729ddda3fcf2ba7524d31060b3ba16cae44ecd361de7553294df3d59ad3989c718c88b0fc380abdf1141820f858e49793ebc1af9d962bf2a2bbba5476a5f
7
- data.tar.gz: c6783e3531abb481ef782896abc61fa13a87fcbfb4bcee8abd2e018006cd62c7ee4e8bc60b57dc747f17e25c3d9540c4dc7c3820b05ad8c2652883241b807397
6
+ metadata.gz: e60500bfbfcbeabaa14011563aa048c082e550beecb26f4d7260f5f489dfad909103319fb3a056251ea87030c7a0ea8b92198c6eab3d49cc7ccf2dce19f89e7a
7
+ data.tar.gz: 39a2d4eeccccbfd9be6845cff51c8316975a9cfb7334c062914abc1c0051e14abbcb31c1b64e808dd5c0fdb8c0ede9a91a61f50e93fc1904c7903348009f7a27
data/bin/chopin CHANGED
@@ -1,6 +1,73 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'chopin'
3
+ require "erb"
4
+ require "fileutils"
5
+ require "pygments"
6
+ require "redcarpet"
7
+ require "./lib/pygments_renderer"
4
8
 
5
- chopin = Chopin.new(ARGV[0], ARGV[1])
6
- chopin.build
9
+ BLUE = "\033[0;34m"
10
+ GREEN = "\033[0;32m"
11
+ PURPLE = "\033[0;35m"
12
+ RED = "\033[0;31m"
13
+ WHITE = "\033[0m"
14
+
15
+ MARKDOWN = Redcarpet::Markdown.new(PygmentsRenderer,
16
+ disable_indented_code_blocks: true,
17
+ fenced_code_blocks: true,
18
+ footnotes: true,
19
+ no_intra_emphasis: true,
20
+ prettify: true,
21
+ quote: true,
22
+ tables: true
23
+ )
24
+
25
+ def copy(source, destination, layout = nil)
26
+ if File.directory?(source)
27
+ unless Dir.exists?(destination)
28
+ Dir.mkdir(destination)
29
+ puts " #{GREEN}Create#{WHITE} #{destination}"
30
+ end
31
+
32
+ source_directory = Dir.new(source)
33
+ destination_directory = Dir.new(destination)
34
+
35
+ layout = "#{source}/layout.erb" if File.exist?("#{source}/layout.erb")
36
+
37
+ source_directory.each do |file|
38
+ next if file == "." || file == ".."
39
+
40
+ if file[0] == "."
41
+ puts " #{RED}Ignore#{WHITE} #{source}/#{file}"
42
+ next
43
+ end
44
+
45
+ copy("#{source}/#{file}", "#{destination}/#{file}", layout)
46
+ end
47
+ else
48
+ case File.extname(source)
49
+ when ".erb"
50
+ unless File.basename(source) == "layout.erb"
51
+ destination_html = destination.sub(".erb", ".html")
52
+ puts " #{PURPLE}Parse#{WHITE} #{source} (into #{layout}) -> #{destination_html}"
53
+ render = Proc.new { ERB.new(File.read(source)).result }
54
+ output = ERB.new(File.read(layout)).result(nil, &render)
55
+ File.new(destination_html, "w").write(output)
56
+ end
57
+
58
+ when ".md"
59
+ destination_html = destination.sub(".md", ".html")
60
+ puts " #{PURPLE}Parse#{WHITE} #{source} (into #{layout}) -> #{destination_html}"
61
+ #render = Proc.new { GitHub::Markup.render(source) }
62
+ render = Proc.new { MARKDOWN.render(File.new(source).read) }
63
+ output = ERB.new(File.read(layout)).result(nil, &render)
64
+ File.new(destination_html, "w").write(output)
65
+
66
+ else
67
+ puts " #{BLUE}Copy#{WHITE} #{source} -> #{destination}"
68
+ FileUtils.cp(source, destination)
69
+ end
70
+ end
71
+ end
72
+
73
+ copy(ARGV[0], ARGV[1])
@@ -0,0 +1,5 @@
1
+ class PygmentsRenderer < Redcarpet::Render::HTML
2
+ def block_code(code, language)
3
+ Pygments.highlight(code, lexer: language)
4
+ end
5
+ end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chopin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Forisha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-08 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pygments.rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.3
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: redcarpet
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - '='
18
32
  - !ruby/object:Gem::Version
19
- version: 3.2.3
33
+ version: 3.3.2
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - '='
25
39
  - !ruby/object:Gem::Version
26
- version: 3.2.3
40
+ version: 3.3.2
27
41
  description: An elegant, simple static site generator
28
42
  email: josh@forisha.com
29
43
  executables:
@@ -31,8 +45,8 @@ executables:
31
45
  extensions: []
32
46
  extra_rdoc_files: []
33
47
  files:
48
+ - lib/pygments_renderer.rb
34
49
  - bin/chopin
35
- - lib/chopin.rb
36
50
  homepage: https://github.com/joshforisha/chopin
37
51
  licenses:
38
52
  - MIT
@@ -43,17 +57,17 @@ require_paths:
43
57
  - lib
44
58
  required_ruby_version: !ruby/object:Gem::Requirement
45
59
  requirements:
46
- - - ">="
60
+ - - '>='
47
61
  - !ruby/object:Gem::Version
48
62
  version: '0'
49
63
  required_rubygems_version: !ruby/object:Gem::Requirement
50
64
  requirements:
51
- - - ">="
65
+ - - '>='
52
66
  - !ruby/object:Gem::Version
53
67
  version: '0'
54
68
  requirements: []
55
69
  rubyforge_project:
56
- rubygems_version: 2.4.5
70
+ rubygems_version: 2.0.14
57
71
  signing_key:
58
72
  specification_version: 4
59
73
  summary: Chopin
data/lib/chopin.rb DELETED
@@ -1,94 +0,0 @@
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
-
11
- class Chopin
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}/", '')
93
- end
94
- end