pakman 0.2.0 → 0.3.0

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.
data/Manifest.txt CHANGED
@@ -7,6 +7,7 @@ lib/pakman.rb
7
7
  lib/pakman/cli/commands/fetch.rb
8
8
  lib/pakman/cli/commands/gen.rb
9
9
  lib/pakman/cli/commands/list.rb
10
+ lib/pakman/cli/ctx.rb
10
11
  lib/pakman/cli/helpers.rb
11
12
  lib/pakman/cli/opts.rb
12
13
  lib/pakman/cli/runner.rb
@@ -14,4 +15,6 @@ lib/pakman/copier.rb
14
15
  lib/pakman/fetcher.rb
15
16
  lib/pakman/finder.rb
16
17
  lib/pakman/manifest.rb
18
+ lib/pakman/template.rb
19
+ lib/pakman/templater.rb
17
20
  lib/pakman/version.rb
data/lib/pakman.rb CHANGED
@@ -8,6 +8,7 @@
8
8
 
9
9
  require 'yaml'
10
10
  require 'pp'
11
+ require 'erb'
11
12
  require 'logger'
12
13
  require 'optparse'
13
14
  require 'fileutils'
@@ -22,8 +23,11 @@ require 'pakman/copier'
22
23
  require 'pakman/fetcher'
23
24
  require 'pakman/finder'
24
25
  require 'pakman/manifest'
26
+ require 'pakman/template'
27
+ require 'pakman/templater'
25
28
  require 'pakman/version'
26
29
 
30
+ require 'pakman/cli/ctx'
27
31
  require 'pakman/cli/helpers'
28
32
  require 'pakman/cli/opts'
29
33
  require 'pakman/cli/runner'
@@ -2,29 +2,25 @@ module Pakman
2
2
 
3
3
  class Fetch
4
4
 
5
+ attr_reader :logger, :opts
6
+
5
7
  def initialize( logger, opts )
6
8
  @logger = logger
7
9
  @opts = opts
8
10
  end
9
11
 
10
- attr_reader :logger, :opts
11
-
12
-
13
12
  def run
14
- logger.debug "fetch_uri=#{opts.fetch_uri}"
15
-
13
+ logger.debug "fetch_uri: >#{opts.fetch_uri}<"
16
14
  src = opts.fetch_uri
17
15
 
18
- # src = 'http://github.com/geraldb/slideshow/raw/d98e5b02b87ee66485431b1bee8fb6378297bfe4/code/templates/fullerscreen.txt'
19
- # src = 'http://github.com/geraldb/sandbox/raw/13d4fec0908fbfcc456b74dfe2f88621614b5244/s5blank/s5blank.txt'
20
16
  uri = URI.parse( src )
21
- logger.debug "scheme: #{uri.scheme}, host: #{uri.host}, port: #{uri.port}, path: #{uri.path}"
17
+ logger.debug "scheme: >#{uri.scheme}<, host: >#{uri.host}<, port: >#{uri.port}<, path: >#{uri.path}<"
22
18
 
23
- basename = File.basename( uri.path, '.*' ) # e.g. fullerscreen (without extension)
24
- logger.debug "basename: #{basename}"
19
+ pakname = File.basename( uri.path ).downcase.gsub( '.txt', '' )
20
+ logger.debug "pakname: >#{pakname}<"
25
21
 
26
- pakpath = File.expand_path( "#{opts.config_path}/#{basename}" )
27
- logger.debug "pakpath: #{pakpath}"
22
+ pakpath = File.expand_path( "#{opts.config_path}/#{pakname}" )
23
+ logger.debug "pakpath: >#{pakpath}<"
28
24
 
29
25
  Fetcher.new( logger ).fetch_pak( src, pakpath )
30
26
  end # method run
@@ -11,31 +11,35 @@ class Gen
11
11
 
12
12
  attr_reader :logger, :opts
13
13
 
14
- def run
14
+ def run( args )
15
15
  manifest_name = opts.manifest
16
-
17
- # add .txt file extension if missing (for convenience)
18
- ## fix: might not work with impress.js or deck.js
19
- ## check if extname is txt and add it to become deck.js.txt etc.
20
- manifest_name << ".txt" if File.extname( manifest_name ).empty?
16
+ manifest_name = manifest_name.downcase.gsub('.txt', '' ) # remove .txt if present
21
17
 
22
18
  logger.debug "manifest=#{manifest_name}"
23
-
24
- manifests = installed_template_manifests
25
-
26
- # check for builtin generator manifests
27
- matches = manifests.select { |m| m[0] == manifest_name }
28
-
29
- if matches.empty?
30
- puts "*** error: unknown template manifest '#{manifest_name}'"
31
- # todo: list installed manifests
19
+
20
+ # check for matching manifests
21
+ manifests = installed_template_manifests.select { |m| m[0] == manifest_name+'.txt' }
22
+
23
+ if manifests.empty?
24
+ puts "*** error: unknown template pack '#{manifest_name}'; use pakman -l to list installed template packs"
32
25
  exit 2
33
26
  end
34
27
 
35
- manifestsrc = matches[0][1]
28
+ manifestsrc = manifests[0][1]
36
29
  pakpath = opts.output_path
37
30
 
38
- Copier.new( logger ).copy_pak( manifestsrc, pakpath )
31
+ if args.empty?
32
+ Copier.new( logger ).copy_pak( manifestsrc, pakpath )
33
+ else
34
+ args.each do |arg|
35
+ data = YAML.load_file( arg )
36
+ name = File.basename( arg, '.*' )
37
+ puts "#{name}:"
38
+ pp data
39
+ Templater.new( logger ).copy_pak( manifestsrc, pakpath, Ctx.new(data).ctx, name, '--content-todo-remove--' )
40
+ end
41
+ end
42
+
39
43
  end
40
44
 
41
45
  end # class Gen
@@ -25,7 +25,7 @@ class List
25
25
  puts " -- none --"
26
26
  else
27
27
  manifests.each do |manifest|
28
- puts "%16s (%s)" % [manifest[0], manifest[1]]
28
+ puts "%16s (%s)" % [manifest[0].gsub('.txt',''), manifest[1]]
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,32 @@
1
+ module Pakman
2
+
3
+ class Ctx # Context
4
+
5
+ def initialize( hash )
6
+ @hash = hash
7
+ end
8
+
9
+ def ctx
10
+ ### todo: check if method_missing works with binding in erb???
11
+ binding
12
+ end
13
+
14
+ def method_missing( mn, *args, &blk )
15
+ ## only allow read-only access (no arguments)
16
+ if args.length > 0 # || mn[-1].chr == "="
17
+ return super # super( mn, *args, &blk )
18
+ end
19
+
20
+ key = mn.to_sym
21
+
22
+ if @hash.has_key?( key )
23
+ puts "ctx.#{key}"
24
+ @hash[ key ]
25
+ else
26
+ puts "*** ctx.#{key} missing"
27
+ super
28
+ end
29
+ end
30
+
31
+ end # class Ctx
32
+ end # module Pakman
@@ -58,6 +58,8 @@ Examples:
58
58
  pakman -l -c ~/.slideshow/templates
59
59
 
60
60
  pakman -t s6
61
+ pakman -t s6 ruby19.yml
62
+ pakman -t s6 ruby19.yml tagging.yml
61
63
  pakman -t s6 -o o
62
64
  pakman -t s6 -c ~/.slideshow/templates
63
65
 
@@ -76,7 +78,7 @@ EOS
76
78
  if opts.list?
77
79
  List.new( logger, opts ).run
78
80
  elsif opts.generate?
79
- Gen.new( logger, opts ).run
81
+ Gen.new( logger, opts ).run( args )
80
82
  elsif opts.fetch?
81
83
  Fetch.new( logger, opts ).run
82
84
  else
@@ -0,0 +1,20 @@
1
+ module Pakman
2
+
3
+ class Template
4
+
5
+ def initialize( path )
6
+ @path = path
7
+ end
8
+
9
+ def render( binding )
10
+ ERB.new( load_template() ).result( binding )
11
+ end
12
+
13
+ private
14
+ def load_template
15
+ puts " Loading template >#{@path}<..."
16
+ File.read( @path )
17
+ end
18
+
19
+ end # class Template
20
+ end # module Pakman
@@ -0,0 +1,90 @@
1
+ module Pakman
2
+
3
+ class Templater
4
+
5
+ attr_reader :logger
6
+
7
+ def initialize( logger )
8
+ @logger = logger
9
+ end
10
+
11
+
12
+ ## fix/todo:
13
+ ## - get @name or @content from binding - possible with lookup???
14
+
15
+ def copy_pak( manifestsrc, pakpath, binding, name, content )
16
+
17
+ start = Time.now
18
+
19
+ #### fix/todo:
20
+ ## - check for .erb file extension for trigger for erb processing
21
+
22
+ # downcase and remove .txt (if anywhere in name)
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}'"
28
+
29
+ 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
+
44
+ out << Template.new( entry[1] ).render( binding )
45
+
46
+ ## fix: remove entry.size > 2
47
+ ## check template pack and convert to new simple erb classic version
48
+
49
+ if entry.size > 2 # more than one source file? assume header and footer with content added inbetween
50
+ out << content
51
+ out << Template.new( entry[2] ).render( binding )
52
+ end
53
+
54
+ out.flush
55
+ out.close
56
+ else # just copy verbatim if target/dest has no __file__ in name
57
+ dest = entry[0]
58
+ source = entry[1]
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 ) )
65
+ end
66
+ end # each entry in manifest
67
+
68
+ puts "Done (in #{Time.now-start} s)."
69
+ end # method copy_pak
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
88
+
89
+ end # class Templater
90
+ end # module Pakman
@@ -1,3 +1,3 @@
1
1
  module Pakman
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
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: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.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-19 00:00:00 Z
18
+ date: 2012-06-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: fetcher
@@ -81,6 +81,7 @@ files:
81
81
  - lib/pakman/cli/commands/fetch.rb
82
82
  - lib/pakman/cli/commands/gen.rb
83
83
  - lib/pakman/cli/commands/list.rb
84
+ - lib/pakman/cli/ctx.rb
84
85
  - lib/pakman/cli/helpers.rb
85
86
  - lib/pakman/cli/opts.rb
86
87
  - lib/pakman/cli/runner.rb
@@ -88,6 +89,8 @@ files:
88
89
  - lib/pakman/fetcher.rb
89
90
  - lib/pakman/finder.rb
90
91
  - lib/pakman/manifest.rb
92
+ - lib/pakman/template.rb
93
+ - lib/pakman/templater.rb
91
94
  - lib/pakman/version.rb
92
95
  homepage: http://geraldb.github.com/pakman
93
96
  licenses: []