Class: MyMediaKvx
- Inherits:
-
MyMedia::Base
- Object
- MyMedia::Base
- MyMediaKvx
- Defined in:
- lib/mymedia-kvx.rb
Instance Attribute Summary collapse
-
#kvx ⇒ Object
readonly
Returns the value of attribute kvx.
Instance Method Summary collapse
- #copy_publish(filename, raw_msg = '', &blk) ⇒ Object
-
#initialize(public_type: 'kvx', media_type: public_type, config: nil, ext: '.txt', xsl: nil) ⇒ MyMediaKvx
constructor
A new instance of MyMediaKvx.
- #media_path ⇒ Object
Constructor Details
#initialize(public_type: 'kvx', media_type: public_type, config: nil, ext: '.txt', xsl: nil) ⇒ MyMediaKvx
Returns a new instance of MyMediaKvx.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mymedia-kvx.rb', line 14 def initialize(public_type: 'kvx', media_type: public_type, config: nil, ext: '.txt', xsl: nil) @public_type = public_type super(media_type: media_type, public_type: public_type, config: config) @media_src = "%s/media/%s" % [@home, public_type] @prefix = 'k' @target_ext = '.html' @media_type = media_type @ext = ext @xsl = xsl end |
Instance Attribute Details
#kvx ⇒ Object (readonly)
Returns the value of attribute kvx.
12 13 14 |
# File 'lib/mymedia-kvx.rb', line 12 def kvx @kvx end |
Instance Method Details
#copy_publish(filename, raw_msg = '', &blk) ⇒ Object
36 37 38 39 40 41 42 43 44 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/mymedia-kvx.rb', line 36 def copy_publish(filename, raw_msg='', &blk) src_path = File.join(@media_src, filename) raise "file not found : " + src_path unless File.exists? src_path file_publish(src_path, raw_msg) do |destination, raw_destination| raw_dest_xml = raw_destination.sub(/html$/,'xml') dest_xml = destination.sub(/html$/,'xml') if not raw_msg or raw_msg.empty? then raw_msg = File.basename(src_path) + " updated: " + Time.now.to_s end if File.extname(src_path) == '.txt' then kvx, raw_msg = copy_edit(src_path, dest_xml) copy_edit(src_path, raw_dest_xml, xsldir: 'r/xsl') else kvx = Kvx.new(src_path) title = kvx.summary[:title] || '' kvx.summary[:original_source] = File.basename(src_path) File.write dest_xml, kvx.to_s File.write raw_dest_xml, kvx.to_s end # transform the XML to an HTML file #jr010816 File.write raw_destination, # xsltproc("#{@home}/r/xsl/#{@public_type}.xsl", raw_dest_xml) if block_given? then a = blk.call({home: @home, www: @www, destination: destination, dest_xml: dest_xml}) a.each do |xsl, outfile| puts 'xsl: ' + xsl.inspect puts 'outfile: ' + outfile.inspect File.write outfile, xsltproc(xsl, dest_xml) end end File.write destination, \ xsltproc("#{@home}/#{@www}/xsl/#{@public_type}.xsl", dest_xml) if not File.basename(src_path)[/#{@prefix}\d{6}T\d{4}\.txt/] then html_filename = File.basename(src_path).sub(/\.txt$/, @target_ext) FileUtils.cp destination, @home + "/#{@public_type}/" + html_filename if File.extname(src_path) == '.txt' then FileUtils.cp src_path, @home + "/#{@public_type}/" \ + File.basename(src_path) end #publish the static links feed kvx_filepath = @home + "/#{@public_type}/static.xml" target_url = "%s/%s/%s" % [@website, @public_type, html_filename] publish_dynarex(kvx_filepath, {title: html_filename, url: target_url }) end [raw_msg, target_url] end end |
#media_path ⇒ Object
32 33 34 |
# File 'lib/mymedia-kvx.rb', line 32 def media_path() @media_src end |