pakman 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -0
- data/README.markdown +12 -0
- data/lib/pakman.rb +1 -0
- data/lib/pakman/cli/commands/fetch.rb +2 -2
- data/lib/pakman/cli/commands/gen.rb +1 -1
- data/lib/pakman/cli/ctx.rb +7 -4
- data/lib/pakman/copier.rb +12 -29
- data/lib/pakman/fetcher.rb +26 -24
- data/lib/pakman/finder.rb +6 -1
- data/lib/pakman/templater.rb +29 -63
- data/lib/pakman/utils.rb +13 -0
- data/lib/pakman/version.rb +1 -1
- metadata +5 -4
data/Manifest.txt
CHANGED
data/README.markdown
CHANGED
@@ -16,6 +16,13 @@ Copy a template pack from your cache:
|
|
16
16
|
Pakman::Copier.new( logger ).copy_pak( src, pakpath )
|
17
17
|
```
|
18
18
|
|
19
|
+
Merge a template pack from your cache:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Pakman::Templater.new( logger ).merge_pak( src, pakpath, binding, name )
|
23
|
+
```
|
24
|
+
|
25
|
+
|
19
26
|
List all template packs in your cache (using passed in search path):
|
20
27
|
|
21
28
|
```ruby
|
@@ -61,6 +68,11 @@ The [`slideshow`](http://slideshow.rubyforge.org) (also known as Slide Show (S9)
|
|
61
68
|
that lets you create slide shows
|
62
69
|
and author slides in plain text using a wiki-style markup language that's easy-to-write and easy-to-read.
|
63
70
|
|
71
|
+
## Real World Template Packs
|
72
|
+
|
73
|
+
* [S6 Template Pack](https://github.com/geraldb/slideshow-s6-blank)
|
74
|
+
* [impress.js Template Pack](https://github.com/geraldb/slideshow-impress.js)
|
75
|
+
* [deck.js Template Pack](https://github.com/geraldb/slideshow-deck.js)
|
64
76
|
|
65
77
|
## License
|
66
78
|
|
data/lib/pakman.rb
CHANGED
@@ -16,10 +16,10 @@ class Fetch
|
|
16
16
|
uri = URI.parse( src )
|
17
17
|
logger.debug "scheme: >#{uri.scheme}<, host: >#{uri.host}<, port: >#{uri.port}<, path: >#{uri.path}<"
|
18
18
|
|
19
|
-
pakname =
|
19
|
+
pakname = Pakman.pakname_from_file( uri.path )
|
20
20
|
logger.debug "pakname: >#{pakname}<"
|
21
21
|
|
22
|
-
pakpath = File.expand_path(
|
22
|
+
pakpath = File.expand_path( pakname, opts.config_path )
|
23
23
|
logger.debug "pakpath: >#{pakpath}<"
|
24
24
|
|
25
25
|
Fetcher.new( logger ).fetch_pak( src, pakpath )
|
@@ -36,7 +36,7 @@ class Gen
|
|
36
36
|
name = File.basename( arg, '.*' )
|
37
37
|
puts "#{name}:"
|
38
38
|
pp data
|
39
|
-
Templater.new( logger ).
|
39
|
+
Templater.new( logger ).merge_pak( manifestsrc, pakpath, Ctx.new(data).ctx, name )
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
data/lib/pakman/cli/ctx.rb
CHANGED
@@ -17,13 +17,16 @@ class Ctx # Context
|
|
17
17
|
return super # super( mn, *args, &blk )
|
18
18
|
end
|
19
19
|
|
20
|
-
key = mn.
|
20
|
+
key = mn.to_s
|
21
21
|
|
22
22
|
if @hash.has_key?( key )
|
23
|
-
puts "ctx.#{key}"
|
24
|
-
@hash[ key ]
|
23
|
+
puts "calling ctx.#{key}"
|
24
|
+
value = @hash[ key ]
|
25
|
+
puts " returning #{value.class.name}:"
|
26
|
+
pp value
|
27
|
+
value
|
25
28
|
else
|
26
|
-
puts "***
|
29
|
+
puts "*** warning: ctx.#{key} missing"
|
27
30
|
super
|
28
31
|
end
|
29
32
|
end
|
data/lib/pakman/copier.rb
CHANGED
@@ -12,47 +12,30 @@ class Copier
|
|
12
12
|
|
13
13
|
start = Time.now
|
14
14
|
|
15
|
-
|
16
|
-
# e.g. welcome.quick.txt becomes welcome.quick
|
17
|
-
# welcome.txt.quick becomse welcome.quick
|
18
|
-
pakname = File.basename( manifestsrc ).downcase.gsub( '.txt', '' )
|
15
|
+
pakname = Pakman.pakname_from_file( manifestsrc )
|
19
16
|
|
20
17
|
puts "Copying template pack '#{pakname}'"
|
21
18
|
|
22
19
|
manifest = Manifest.load_file( logger, manifestsrc )
|
23
20
|
|
24
|
-
# expand output path in current dir (if relative) and make sure output path exists
|
25
|
-
outpath = File.expand_path( pakpath )
|
26
|
-
logger.debug "outpath=#{outpath}"
|
27
|
-
FileUtils.makedirs( outpath ) unless File.directory?( outpath )
|
28
|
-
|
29
21
|
manifest.each do |entry|
|
30
22
|
dest = entry[0]
|
31
23
|
source = entry[1]
|
32
|
-
|
24
|
+
|
25
|
+
# get full (absolute) path and make sure path exists
|
26
|
+
destfull = File.expand_path( dest, pakpath )
|
27
|
+
destpath = File.dirname( destfull )
|
28
|
+
FileUtils.makedirs( destpath ) unless File.directory?( destpath )
|
29
|
+
|
30
|
+
logger.debug "destfull=>#{destfull}<"
|
31
|
+
logger.debug "destpath=>#{destpath}<"
|
32
|
+
|
33
33
|
puts " Copying to #{dest} from #{source}..."
|
34
|
-
FileUtils.copy( source,
|
34
|
+
FileUtils.copy( source, destfull )
|
35
35
|
end
|
36
36
|
|
37
37
|
puts "Done (in #{Time.now-start} s)."
|
38
38
|
end # method copy_pak
|
39
39
|
|
40
|
-
private
|
41
|
-
|
42
|
-
############################
|
43
|
-
## fix/todo: cleanup needed
|
44
|
-
## fix: remove with_output_path helper (code it directly w/o helper)
|
45
|
-
|
46
|
-
def with_output_path( dest, output_path )
|
47
|
-
dest_full = File.expand_path( dest, output_path )
|
48
|
-
logger.debug "dest_full=#{dest_full}"
|
49
|
-
|
50
|
-
# make sure dest path exists
|
51
|
-
dest_path = File.dirname( dest_full )
|
52
|
-
logger.debug "dest_path=#{dest_path}"
|
53
|
-
FileUtils.makedirs( dest_path ) unless File.directory? dest_path
|
54
|
-
dest_full
|
55
|
-
end
|
56
|
-
|
57
40
|
end # class Copier
|
58
|
-
end # module Pakman
|
41
|
+
end # module Pakman
|
data/lib/pakman/fetcher.rb
CHANGED
@@ -13,8 +13,6 @@ class Fetcher
|
|
13
13
|
|
14
14
|
start = Time.now
|
15
15
|
|
16
|
-
# src = 'http://github.com/geraldb/slideshow/raw/d98e5b02b87ee66485431b1bee8fb6378297bfe4/code/templates/fullerscreen.txt'
|
17
|
-
# src = 'http://github.com/geraldb/sandbox/raw/13d4fec0908fbfcc456b74dfe2f88621614b5244/s5blank/s5blank.txt'
|
18
16
|
uri = URI.parse( manifestsrc )
|
19
17
|
|
20
18
|
logger.debug "scheme: #{uri.scheme}, host: #{uri.host}, port: #{uri.port}, path: #{uri.path}"
|
@@ -22,16 +20,14 @@ class Fetcher
|
|
22
20
|
dirname = File.dirname( uri.path )
|
23
21
|
filename = File.basename( uri.path ) # e.g. fullerscreen.txt (with extension)
|
24
22
|
|
25
|
-
|
26
|
-
# e.g. welcome.quick.txt becomes welcome.quick
|
27
|
-
# welcome.txt.quick becomse welcome.quick
|
28
|
-
pakname = File.basename( uri.path ).downcase.gsub( '.txt', '' )
|
23
|
+
pakname = Pakman.pakname_from_file( uri.path )
|
29
24
|
|
30
25
|
logger.debug "dirname >#{dirname}<"
|
31
|
-
logger.debug "
|
26
|
+
logger.debug "filename >#{filename}<"
|
27
|
+
logger.debug "pakname >#{pakname}<"
|
32
28
|
|
33
29
|
dlbase = "#{uri.scheme}://#{uri.host}:#{uri.port}#{dirname}"
|
34
|
-
logger.debug "
|
30
|
+
logger.debug "dlbase: #{dlbase}"
|
35
31
|
logger.debug "pakpath: #{pakpath}"
|
36
32
|
|
37
33
|
FileUtils.makedirs( pakpath ) unless File.directory?( pakpath )
|
@@ -40,30 +36,36 @@ class Fetcher
|
|
40
36
|
puts " from '#{dlbase}'"
|
41
37
|
puts " saving to '#{pakpath}'"
|
42
38
|
|
43
|
-
# download manifest
|
44
|
-
|
39
|
+
# step 1: download manifest
|
40
|
+
manifestdest = "#{pakpath}/#{filename}"
|
45
41
|
|
46
42
|
puts " Downloading manifest '#{filename}'..."
|
47
43
|
|
48
|
-
fetch_file( manifestsrc,
|
44
|
+
fetch_file( manifestsrc, manifestdest )
|
49
45
|
|
50
|
-
manifest = Manifest.load_file_core( logger,
|
46
|
+
manifest = Manifest.load_file_core( logger, manifestdest )
|
51
47
|
|
52
|
-
# download templates listed in manifest
|
53
|
-
manifest.each do |
|
54
|
-
|
55
|
-
|
56
|
-
dest = "#{pakpath}/#{file}"
|
48
|
+
# step 2: download files & templates listed in manifest
|
49
|
+
manifest.each do |entry|
|
50
|
+
source = entry[1]
|
57
51
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
52
|
+
# get full (absolute) path and make sure path exists
|
53
|
+
destfull = File.expand_path( source, pakpath ) # NB: turning source into dest
|
54
|
+
destpath = File.dirname( destfull )
|
55
|
+
FileUtils.makedirs( destpath ) unless File.directory?( destpath )
|
56
|
+
|
57
|
+
logger.debug "destfull=>#{destfull}<"
|
58
|
+
logger.debug "destpath=>#{destpath}<"
|
59
|
+
|
60
|
+
sourcefull = "#{dlbase}/#{source}"
|
63
61
|
|
64
|
-
|
65
|
-
|
62
|
+
if source =~ /\.erb\.|.erb$/
|
63
|
+
puts " Downloading template '#{source}'..."
|
64
|
+
else
|
65
|
+
puts " Downloading file '#{source}'..."
|
66
66
|
end
|
67
|
+
|
68
|
+
fetch_file( sourcefull, destfull )
|
67
69
|
end
|
68
70
|
puts "Done (in #{Time.now-start} s)."
|
69
71
|
end # method fetch_pak
|
data/lib/pakman/finder.rb
CHANGED
@@ -21,6 +21,11 @@ class Finder
|
|
21
21
|
else
|
22
22
|
unless exclude?( file, excludes ) # check for excludes; skip if excluded
|
23
23
|
logger.debug " Adding match >#{file}<"
|
24
|
+
|
25
|
+
## todo/fix:
|
26
|
+
# array first entry - downcase and gsub('.txt','') ??
|
27
|
+
# use Pakman.pakname_from_file()
|
28
|
+
|
24
29
|
manifests << [ File.basename( file ), file ]
|
25
30
|
end
|
26
31
|
end
|
@@ -35,7 +40,7 @@ private
|
|
35
40
|
excludes.each do |pattern|
|
36
41
|
## todo: FNM_DOTMATCH helps or not?? (make up some tests??)
|
37
42
|
if File.fnmatch?( pattern, file, File::FNM_CASEFOLD | File::FNM_DOTMATCH )
|
38
|
-
logger.debug " Skipping match; it's excluded by pattern >#{pattern}<"
|
43
|
+
logger.debug " Skipping match; it's excluded by pattern >#{pattern}<"
|
39
44
|
return true
|
40
45
|
end
|
41
46
|
end
|
data/lib/pakman/templater.rb
CHANGED
@@ -7,84 +7,50 @@ class Templater
|
|
7
7
|
def initialize( logger )
|
8
8
|
@logger = logger
|
9
9
|
end
|
10
|
-
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def copy_pak( manifestsrc, pakpath, binding, name, content )
|
11
|
+
|
12
|
+
def merge_pak( manifestsrc, pakpath, binding, name )
|
16
13
|
|
17
14
|
start = Time.now
|
18
15
|
|
19
|
-
|
20
|
-
## - check for .erb file extension for trigger for erb processing
|
16
|
+
pakname = Pakman.pakname_from_file( manifestsrc )
|
21
17
|
|
22
|
-
|
23
|
-
# e.g. welcome.quick.txt becomes welcome.quick
|
24
|
-
# welcome.txt.quick becomse welcome.quick
|
25
|
-
pakname = File.basename( manifestsrc ).downcase.gsub( '.txt', '' )
|
26
|
-
|
27
|
-
puts "Copying template pack '#{pakname}'"
|
18
|
+
puts "Merging template pack '#{pakname}'"
|
28
19
|
|
29
20
|
manifest = Manifest.load_file( logger, manifestsrc )
|
30
|
-
|
31
|
-
# expand output path in current dir (if relative) and make sure output path exists
|
32
|
-
outpath = File.expand_path( pakpath )
|
33
|
-
logger.debug "outpath=#{outpath}"
|
34
|
-
FileUtils.makedirs( outpath ) unless File.directory?( outpath )
|
35
|
-
|
36
|
-
manifest.each do |entry|
|
37
|
-
outname = entry[0]
|
38
|
-
if outname.include?( '__file__' ) # process
|
39
|
-
outname = outname.gsub( '__file__', name )
|
40
|
-
puts "Preparing #{outname}..."
|
41
|
-
|
42
|
-
out = File.new( with_output_path( outname, outpath ), 'w+' )
|
43
21
|
|
44
|
-
|
22
|
+
manifest.each do |entry|
|
23
|
+
dest = entry[0]
|
24
|
+
source = entry[1]
|
45
25
|
|
46
|
-
|
47
|
-
|
26
|
+
if dest =~ /__file__/ # replace w/ name
|
27
|
+
dest = dest.gsub( '__file__', name )
|
28
|
+
end
|
48
29
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
30
|
+
# get full (absolute) path and make sure path exists
|
31
|
+
destfull = File.expand_path( dest, pakpath )
|
32
|
+
destpath = File.dirname( destfull )
|
33
|
+
FileUtils.makedirs( destpath ) unless File.directory?( destpath )
|
34
|
+
|
35
|
+
logger.debug "destfull=>#{destfull}<"
|
36
|
+
logger.debug "destpath=>#{destpath}<"
|
37
|
+
|
38
|
+
if source =~ /\.erb\.|.erb$/
|
39
|
+
puts " Merging to #{dest}..."
|
40
|
+
|
41
|
+
out = File.new( destfull, 'w+' )
|
42
|
+
out << Template.new( source ).render( binding )
|
54
43
|
out.flush
|
55
44
|
out.close
|
56
|
-
else
|
57
|
-
dest
|
58
|
-
|
59
|
-
|
60
|
-
#### fix/todo:
|
61
|
-
# - check for .erb file extension for trigger for erb processing
|
62
|
-
|
63
|
-
puts "Copying to #{dest} from #{source}..."
|
64
|
-
FileUtils.copy( source, with_output_path( dest, outpath ) )
|
45
|
+
else
|
46
|
+
puts " Copying to #{dest} from #{source}..."
|
47
|
+
|
48
|
+
FileUtils.copy( source, destfull )
|
65
49
|
end
|
66
50
|
end # each entry in manifest
|
67
51
|
|
68
|
-
puts "Done (in #{Time.now-start} s)."
|
69
|
-
end # method
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
|
74
|
-
############################
|
75
|
-
## fix/todo: cleanup needed
|
76
|
-
## fix: remove with_output_path helper (code it directly w/o helper)
|
77
|
-
|
78
|
-
def with_output_path( dest, output_path )
|
79
|
-
dest_full = File.expand_path( dest, output_path )
|
80
|
-
logger.debug "dest_full=#{dest_full}"
|
81
|
-
|
82
|
-
# make sure dest path exists
|
83
|
-
dest_path = File.dirname( dest_full )
|
84
|
-
logger.debug "dest_path=#{dest_path}"
|
85
|
-
FileUtils.makedirs( dest_path ) unless File.directory? dest_path
|
86
|
-
dest_full
|
87
|
-
end
|
52
|
+
puts "Done (in #{Time.now-start} s)."
|
53
|
+
end # method merge_pak
|
88
54
|
|
89
55
|
end # class Templater
|
90
56
|
end # module Pakman
|
data/lib/pakman/utils.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Pakman
|
2
|
+
|
3
|
+
|
4
|
+
# downcase and remove .txt (if anywhere in name)
|
5
|
+
# e.g. welcome.quick.txt becomes welcome.quick
|
6
|
+
# welcome.txt.quick becomse welcome.quick
|
7
|
+
# s6blank.txt becomes s6blank
|
8
|
+
|
9
|
+
def self.pakname_from_file( path )
|
10
|
+
File.basename( path ).downcase.gsub( '.txt', '' )
|
11
|
+
end
|
12
|
+
|
13
|
+
end # class Pakman
|
data/lib/pakman/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pakman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gerald Bauer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-06-
|
18
|
+
date: 2012-06-22 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: fetcher
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/pakman/manifest.rb
|
92
92
|
- lib/pakman/template.rb
|
93
93
|
- lib/pakman/templater.rb
|
94
|
+
- lib/pakman/utils.rb
|
94
95
|
- lib/pakman/version.rb
|
95
96
|
homepage: http://geraldb.github.com/pakman
|
96
97
|
licenses: []
|