hpp 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/hpp +2 -2
- data/lib/hpp/hpp.rb +65 -0
- data/lib/hpp/version.rb +3 -0
- metadata +22 -5
- data/lib/hpp.rb +0 -37
data/bin/hpp
CHANGED
data/lib/hpp/hpp.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'listen'
|
4
|
+
|
5
|
+
module Hpp
|
6
|
+
class Hpp < Thor
|
7
|
+
include FileUtils
|
8
|
+
|
9
|
+
desc 'process SRC TARGET', 'process HTML files under SRC folder to TARGET folder'
|
10
|
+
method_options :daemon => false
|
11
|
+
def process(src='src', target='target')
|
12
|
+
raise RuntimeError.new("There is NO '#{src}' folder in current working directory") unless Dir.exists?(src)
|
13
|
+
Dir.mkdir(target) unless Dir.exists?(target)
|
14
|
+
|
15
|
+
if options.daemon?
|
16
|
+
Listen.to(src, :relative_paths => true) do |modified, added, removed|
|
17
|
+
_process(src, target)
|
18
|
+
print "Changes of files from '#{src}' Detected: "
|
19
|
+
print "#{modified} Modified, " unless modified.empty?
|
20
|
+
print "#{added} Added, " unless added.empty?
|
21
|
+
print "#{removed} Removed, " unless removed.empty?
|
22
|
+
puts "And Re-Generated output files into '#{target}'"
|
23
|
+
end.start
|
24
|
+
elsif
|
25
|
+
_process(src, target)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def _process(src, target)
|
31
|
+
Dir.glob(File.expand_path('*.html', src)) do |src_path|
|
32
|
+
next if src_path.include? '_'
|
33
|
+
File.open(src_path.sub(src, target), 'w') do |output_html|
|
34
|
+
File.open(src_path, 'r') do |source_html|
|
35
|
+
while line = source_html.gets
|
36
|
+
r = /<!--#include src=['"](?<file>.*)['"]-->/.match line
|
37
|
+
if r.nil?
|
38
|
+
output_html.puts line
|
39
|
+
else
|
40
|
+
include_html = File.open(File.expand_path(r[:file], src), 'r').read
|
41
|
+
output_html.puts "<!--include file '#{r[:file]}' Begin-->"
|
42
|
+
output_html.puts include_html
|
43
|
+
output_html.puts "<!--include file '#{r[:file]}' End-->"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Dir.foreach(src) do |file|
|
51
|
+
next if /^\.+/.match file
|
52
|
+
file = File.expand_path(file, src)
|
53
|
+
cp_r file, target if File.directory?(file)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
=begin
|
58
|
+
desc 'new project files', 'create a new HPP project'
|
59
|
+
def new(name)
|
60
|
+
raise RuntimeError.new("There is NO '#{src}' folder in current working directory") unless Dir.exists?(src)
|
61
|
+
|
62
|
+
end
|
63
|
+
=end
|
64
|
+
end
|
65
|
+
end
|
data/lib/hpp/version.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hpp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -27,7 +27,23 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.16.0
|
30
|
-
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: listen
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.5.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.5.3
|
46
|
+
description: This is a very simple command line tool for HTML file pre-processing
|
31
47
|
email:
|
32
48
|
- skyairmj@gmail.com
|
33
49
|
executables:
|
@@ -35,7 +51,8 @@ executables:
|
|
35
51
|
extensions: []
|
36
52
|
extra_rdoc_files: []
|
37
53
|
files:
|
38
|
-
- lib/hpp.rb
|
54
|
+
- lib/hpp/hpp.rb
|
55
|
+
- lib/hpp/version.rb
|
39
56
|
- bin/hpp
|
40
57
|
homepage: https://github.com/mingjin/hpp
|
41
58
|
licenses: []
|
@@ -51,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
68
|
version: '0'
|
52
69
|
segments:
|
53
70
|
- 0
|
54
|
-
hash: -
|
71
|
+
hash: -1079317564156939545
|
55
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
73
|
none: false
|
57
74
|
requirements:
|
data/lib/hpp.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require "thor"
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
class Hpp < Thor
|
5
|
-
include FileUtils
|
6
|
-
|
7
|
-
desc "process SRC TARGET", "process HTML files under SRC folder to TARGET folder"
|
8
|
-
def process(src='src', target='target')
|
9
|
-
raise RuntimeError.new("There is NO '#{src}' folder in current working directory") unless Dir.exists?(src)
|
10
|
-
Dir.mkdir(target) unless Dir.exists?(target)
|
11
|
-
|
12
|
-
Dir.glob(File.expand_path('*.html', src)) do |src_path|
|
13
|
-
next if src_path.include? '_'
|
14
|
-
File.open(src_path.sub(src, target), 'w') do |output_html|
|
15
|
-
File.open(src_path, 'r') do |source_html|
|
16
|
-
while line = source_html.gets
|
17
|
-
r = /<!--#include src=['"](?<file>.*)['"]-->/.match line
|
18
|
-
if r.nil?
|
19
|
-
output_html.puts line
|
20
|
-
else
|
21
|
-
include_html = File.open(File.expand_path(r[:file], src), 'r').read
|
22
|
-
output_html.puts "<!--include file '#{r[:file]}' Begin-->"
|
23
|
-
output_html.puts include_html
|
24
|
-
output_html.puts "<!--include file '#{r[:file]}' End-->"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
Dir.foreach(src) do |file|
|
32
|
-
next if /^\.+/.match file
|
33
|
-
file = File.expand_path(file, src)
|
34
|
-
cp_r file, target if File.directory?(file)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|