Sha256: f1bbb4c1377229d4aacdc7b765aee101fd1f0adb259945cc11e8e677f815aa38
Contents?: true
Size: 971 Bytes
Versions: 2
Compression:
Stored size: 971 Bytes
Contents
namespace :txtblx do desc "Import Textblocks from files" task import: :environment do txtdir = Rails.root.join('textblocks') puts "Looking for markdown files in #{txtdir}" Dir.glob(File.join(txtdir, "*.md")) do |mdfile| key = File.basename(mdfile, '.md') puts "Processing key '#{key}'" Txtblx::Textblock.find_or_create_by(key: key) do |txtb| description_indicator = '->' lines = File.readlines(mdfile) first_line = lines.first.strip if first_line.start_with?(description_indicator) description = first_line[description_indicator.length, first_line.length] content = lines[1, lines.length].join("\n") else description = key content = lines.join("\n") end puts " -- Created Textblock (#{description})" txtb.text = content txtb.description = description txtb.save txtb.publish end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
txtblx-0.0.4 | lib/tasks/txtblx_tasks.rake |
txtblx-0.0.3 | lib/tasks/txtblx_tasks.rake |