ssi 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.
data/bin/ssi ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ssi/cli'
4
+
5
+ SSI::CLI.run
data/lib/ssi/cli.rb ADDED
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ #require 'subcommand'
5
+ require 'optparse'
6
+ require 'ssi'
7
+ require 'ssi/version'
8
+ autoload :Console_logger, "ssi/console_logger"
9
+ autoload :FileUtils, "fileutils"
10
+
11
+ module SSI
12
+ class CLI
13
+ class << self
14
+ COL_WIDTH = 40
15
+
16
+ def ask_confirm(question)
17
+ print question
18
+ answer = $stdin.gets.chomp
19
+ accepted_confirms = ['y','yes']
20
+ accepted_confirms.include?(answer.downcase)
21
+ end
22
+
23
+ def run
24
+ @logger = Console_logger
25
+ options = {}
26
+ optparse = OptionParser.new do |opts|
27
+ options[:root_dir] = '.'
28
+ opts.banner = "Usage: ", $PROGRAM_NAME, " [options] filename [filename] [...]"
29
+
30
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
31
+ options[:verbose] = v
32
+ end
33
+
34
+ opts.on("-d", "--root-dir [DIR]", "The directory considered to be the document root") do |d|
35
+ options[:root_dir] = d
36
+ end
37
+
38
+ opts.on("-i", "--inplace [EXTENSION]",
39
+ "Edit ARGV files in place",
40
+ " (make backup if EXTENSION supplied)") do |ext|
41
+ options[:inplace] = true
42
+ options[:extension] = ext || ''
43
+ options[:extension].sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
44
+ end
45
+
46
+ opts.on_tail("-h", "--help", "Show this message") do
47
+ puts opts
48
+ exit
49
+ end
50
+
51
+ opts.on_tail("--version", "Show version") do
52
+ puts VERSION
53
+ exit
54
+ end
55
+ end
56
+
57
+ optparse.parse!
58
+
59
+ (puts optparse.help; exit 1) if ARGV.empty?
60
+ ARGV.each do |fdname|
61
+ @logger.debug("Reading file '#{fdname}'") if options[:verbose]
62
+ dir_path = File::dirname(File::expand_path(fdname))
63
+ @logger.debug("Path:'#{dir_path}'") if options[:verbose]
64
+ ssi_obj = SSI.new(options)
65
+ content = ssi_obj.ssi(dir_path, File.read(fdname))
66
+ if options[:inplace]
67
+ #File.copy(fdname, fdname + options[:extension]) if options[:extension]
68
+ FileUtils.cp(fdname, fdname + options[:extension]) if (options[:extension] != '')
69
+ File.open(fdname, 'w') do |fd|
70
+ fd.write(content)
71
+ end
72
+ else
73
+ puts content
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
data/lib/ssi/config.rb ADDED
@@ -0,0 +1,27 @@
1
+ module SSI
2
+ class Config
3
+ class << self
4
+ def load(file_list)
5
+ @config = {}
6
+ file_list.each do |cfg_file|
7
+ cfg_file = File.expand_path(cfg_file)
8
+ @config.merge!(YAML.load(File.read(cfg_file))) if File.exist?(cfg_file)
9
+ end
10
+ @config
11
+ end
12
+
13
+ def load_handlers
14
+ @config['ssi']['queues'].keys.each do |queue|
15
+ (SSI.warn("Queue '#{queue}' is not configured with a handler");next) if @config['ssi']['queues'][queue]['handlers'].nil?
16
+ handlers = @config['ssi']['queues'][queue]['handlers'].keys
17
+ handlers.each { |handler| require "ssi/handlers/#{handler.downcase}" }
18
+ end
19
+ end
20
+
21
+ def [](key)
22
+ @config[key]
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ module SSI
2
+ module Console_logger
3
+ autoload :Util, "ssi/util"
4
+
5
+ class << self
6
+ def info(msg)
7
+ STDOUT.puts("INFO: %s: %s" % [Util.get_timestamp_utc.to_s, msg])
8
+ end
9
+ def warn(msg)
10
+ STDERR.puts("WARN: %s: %s" % [Util.get_timestamp_utc.to_s, msg])
11
+ end
12
+
13
+ def debug(msg)
14
+ STDERR.puts("DEBUG: %s: %s" % [Util.get_timestamp_utc.to_s, msg])
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/ssi/util.rb ADDED
@@ -0,0 +1,18 @@
1
+ module SSI
2
+ module Util
3
+ module_function
4
+
5
+ def config_files
6
+ cfg_file_paths = ['/etc/ssi/config.yml']
7
+ if ENV['HOME']
8
+ cfg_file_paths << '~/.ssi/config.yml'
9
+ end
10
+ cfg_file_paths
11
+ end
12
+
13
+ def get_timestamp_utc
14
+ Time.now.utc
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module SSI
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ssi.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+ require 'pp'
3
+
4
+ module SSI
5
+ class SSI
6
+ autoload :Console_logger, "ssi/console_logger"
7
+
8
+ @logger = Console_logger
9
+
10
+ SSICommands = {
11
+ :include => 'ssi_include',
12
+ }
13
+
14
+ attr_reader :options
15
+
16
+ class << self
17
+ def info(msg); @logger.info(msg); end
18
+ def warn(msg); @logger.warn(msg); end
19
+ def debug(msg); @logger.debug(msg); end
20
+
21
+ end
22
+
23
+ def initialize(options = {})
24
+ @options = options
25
+ end
26
+
27
+ def ssi_include(dir_path, kvs)
28
+ include_content = ''
29
+ kvs.each do |type,filelist|
30
+ filelist.each do |fdname|
31
+ if (fdname[0,1] == '/')
32
+ fdname.gsub!(/^\//,'')
33
+ file_path = File::expand_path(fdname, @options[:root_dir])
34
+ else
35
+ file_path = File::expand_path(fdname, dir_path)
36
+ end
37
+ new_dir_path = File::dirname(file_path)
38
+ SSI.debug("Including content from #{file_path}") if @options[:verbose]
39
+ include_content << ssi(new_dir_path, File.read(file_path))
40
+ end
41
+ end
42
+ include_content
43
+ end
44
+
45
+ def ssi_parser(ssi)
46
+ cmd, attr_val_pairs_str = ssi.split
47
+ kvs = {}
48
+ attr_val_pairs_str.split().each do |ks|
49
+ attrib, val = ks.split('=')
50
+ kvs[attrib.to_sym] ||= []
51
+ kvs[attrib.to_sym] << val.gsub(/^"|"$/,'')
52
+ end
53
+ [cmd, kvs]
54
+ end
55
+
56
+ #
57
+ # scan for ssi commands
58
+ #
59
+ def ssi(dir_path, content)
60
+ outmap = {}
61
+
62
+ content.scan(/(<!--#(.*?)-->)/) do|m|
63
+ outmap[m.first] = {}
64
+ outmap[m.first][:ssi] = m.last.strip # store for processing later
65
+ end
66
+
67
+ outmap.each do|k,v|
68
+ cmd, kvs = ssi_parser(v[:ssi])
69
+ content.sub!(k,send(SSICommands[cmd.to_sym], dir_path, kvs))
70
+ end
71
+
72
+ content
73
+ end
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssi
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Brian Wong
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2013-02-11 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A script which interpolates server-side includes for HTML files
22
+ email: bwong114@gmail.com
23
+ executables:
24
+ - ssi
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/ssi.rb
31
+ - lib/ssi/cli.rb
32
+ - lib/ssi/config.rb
33
+ - lib/ssi/console_logger.rb
34
+ - lib/ssi/util.rb
35
+ - lib/ssi/version.rb
36
+ - bin/ssi
37
+ has_rdoc: true
38
+ homepage: https://github.com/bwong114/ssi
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.6
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: A script which interpolates server-side includes for HTML files
67
+ test_files: []
68
+