class ActivityLogger
Public Class Methods
new(dirpath=nil, dir: dirpath, xsl_path: nil, config: nil)
click to toggle source
# File lib/activity-logger.rb, line 22 def initialize(dirpath=nil, dir: dirpath, xsl_path: nil, config: nil) @publish_html = false if config then h = SimpleConfig.new(config).to_h dir, @urlbase, @edit_url, @css_url, xsl = \ %i(dir urlbase edit_url css_url xsl_path).map{|x| h[x]} @xsl_path = xsl_path || xsl @publish_html = true end Dir.chdir(dir) if dir end
Public Instance Methods
create(desc='', time=Time.now, id: id=nil)
click to toggle source
# File lib/activity-logger.rb, line 39 def create(desc='', time=Time.now, id: id=nil) ddaily = DynarexDaily.new(nil, xslt: @xsl_path) ddaily.create(time: time.to_s, desc: desc, id: id) ddaily.save if @publish_html then File.write 'index.txt', ddaily.to_s save_html() end end
Private Instance Methods
add(summary, name, s)
click to toggle source
# File lib/activity-logger.rb, line 58 def add(summary, name, s) summary.add Rexle::Element.new(name).add_text s end
render_html(doc)
click to toggle source
# File lib/activity-logger.rb, line 62 def render_html(doc) xslt_buffer = if @xsl_path then buffer, _ = RXFHelper.read @xsl_path buffer else puts 'activity-logger: warning: .xsl file not found, using notices.xsl' fetch_file('notices.xsl') end # jr280416 xslt = Nokogiri::XSLT(xslt_buffer) # jr280416 out = xslt.transform(Nokogiri::XML(doc.xml)) out = Rexslt.new(xslt_buffer, doc.xml).to_s File.write 'index.html', out end
save_html()
click to toggle source
# File lib/activity-logger.rb, line 84 def save_html() newfile = 'formatted.xml' FileUtils.cp 'dynarexdaily.xml', newfile doc = Rexle.new File.read(newfile) summary = doc.root.element('summary') date = Date.today.strftime("%d-%b-%Y").upcase add summary, 'title', date + ' Notices' add summary, 'edit_url', @edit_url summary.element('date').text = date add summary, 'css_url', @css_url add summary, 'published', Time.now.strftime("%d-%m-%Y %H:%M") doc.root.xpath('records/entry') do |entry| e = entry.element('time') e.text = Time.parse(e.text).strftime("%-l:%M%P") desc = entry.element('desc') desc.add Rexle.new("<span>%s</span>" % desc.text.unescape).root desc.text = '' end File.write newfile, doc.xml(pretty: true) render_html doc # save the related CSS file locally if the file doesn't already exist css_file = File.basename @css_url if not File.exists? css_file then File.write css_file, fetch_file('notices.css') end end