Module: PBSimply::Plugger
- Included in:
- PBSimply
- Defined in:
- lib/pbsimply/plugger.rb
Overview
Document tweaking module. Provides deprected Pre-plugins and Post-plugins.
Constant Summary collapse
- POST_PROCESSORS =
{ ".rb" => "ruby", ".pl" => "perl", ".py" => "python", ".lua" => "lua", ".bash" => "bash", ".zsh" => "zsh", ".php" => "php", ".sed" => ["sed", ->(script, target) { ["-f", script, target] } ] }
Instance Method Summary collapse
-
#post_plugins(frontmatter = nil) ⇒ Object
Post plugins invoke each command on .post_generate directory as filter command after processed.
-
#pre_plugins(procdoc, frontmatter) ⇒ Object
Deprecated filter command feature.
Instance Method Details
#post_plugins(frontmatter = nil) ⇒ Object
Post plugins invoke each command on .post_generate directory as filter command after processed. Generated document (typically HTML) path given as first argument.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pbsimply/plugger.rb', line 45 def post_plugins(frontmatter=nil) if File.directory?(".post_generate") STDERR.puts("Processing with post plugins") @this_time_processed.each do |v| STDERR.puts "Processing #{v[:dest]} (from #{v[:source]})" procdoc = v[:dest] frontmatter ||= @indexes[File.basename v[:source]] File.open(@workfile_frontmatter, "w") {|f| f.write JSON_LIB.dump(frontmatter)} Dir.entries(".post_generate").sort.each do |script_file| next if script_file =~ /^\./ STDERR.puts "Running script: #{script_file}" script_file = File.join(".post_generate", script_file) post_script_result = nil script_cmdline = case when File.executable?(script_file) [script_file, procdoc] when POST_PROCESSORS[File.extname(script_file)] [POST_PROCESSORS[File.extname(script_file)], script_file, procdoc] else ["perl", script_file, procdoc] end IO.popen({"pbsimply_workdir" => @workdir,"pbsimply_frontmatter" => @workfile_frontmatter, "pbsimply_indexes" => @db.path}, script_cmdline) do |io| post_script_result = io.read end File.open(procdoc, "w") {|f| f.write post_script_result} end end end end |
#pre_plugins(procdoc, frontmatter) ⇒ Object
Deprecated filter command feature.
Pre plugins invoke each command on .pre_generate directory as filter command before process document. Porcessing document (same content as source document) path given as first argument.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pbsimply/plugger.rb', line 19 def pre_plugins(procdoc, frontmatter) if File.directory?(".pre_generate") STDERR.puts("Processing with pre plugins") script_file = File.join(".pre_generate", script_file) Dir.entries(".pre_generate").sort.each do |script_file| next if script_file =~ /^\./ STDERR.puts "Running script: #{File.basename script_file}" pre_script_result = nil script_cmdline = case when File.executable?(script_file) [script_file, procdoc] when POST_PROCESSORS[File.extname(script_file)] [POST_PROCESSORS[File.extname(script_file)], script_file, procdoc] else ["perl", script_file, procdoc] end IO.popen({"pbsimply_doc_frontmatter" => YAML.dump(frontmatter)}, script_cmdline) do |io| pre_script_result = io.read end File.open(procdoc, "w") {|f| f.write pre_script_result} end end end |