Class: Sibyl::Base
- Inherits:
-
Object
- Object
- Sibyl::Base
- Defined in:
- lib/sibyl/base.rb
Class Method Summary collapse
- .forms(task) ⇒ Object
- .list_columns(task) ⇒ Object
- .list_defaults(task) ⇒ Object
- .load ⇒ Object
- .pages(task, form) ⇒ Object
- .tasks ⇒ Object
Class Method Details
.forms(task) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sibyl/base.rb', line 61 def self.forms(task) dir = Rails.root.join("app", "sibyl", task) filesystem_bag = {} entries = Dir.entries(dir).select {|entry| File.directory? File.join(dir,entry) and !(entry =='.' || entry == '..') } entries.each do |form| name = form.split(/\//).last filesystem_bag['forms'] = [] unless filesystem_bag.has_key? 'forms' filesystem_bag['forms'].push name end begin filesystem_bag['defaults'] = self.list_defaults(task) filesystem_bag['columns'] = self.list_columns(task) rescue Exception => e STDERR.puts "Exception: #{e}: #{e.backtrace}" end return filesystem_bag end |
.list_columns(task) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sibyl/base.rb', line 25 def self.list_columns(task) columns = {} Dir[Rails.root.join("app", "sibyl", task, "*.json").to_s].each do |json_file| json = JSON.parse(File.read(json_file)) json.each_key do |page| if json[page].has_key? 'elements' json[page]['elements'].each_key do |name| if json[page]['elements'][name].has_key? 'column' and json[page]['elements'][name]['column'].to_s == "true" columns[name] = true end end end end end return columns end |
.list_defaults(task) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sibyl/base.rb', line 42 def self.list_defaults(task) defaults = {} Dir[Rails.root.join("app", "sibyl", task, "*.json").to_s].each do |json_file| json = JSON.parse(File.read(json_file)) json.each_key do |page| if json[page].has_key? 'elements' json[page]['elements'].each_key do |name| if json[page]['elements'][name].has_key? 'default' defaults[name] = json[page]['elements'][name]['default'] else defaults[name] = "Default #{name}" end end end end end return defaults end |
.load ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/sibyl/base.rb', line 6 def self.load self.tasks.each do |task| Dir[Rails.root.join("app", "sibyl", task, "*.rb").to_s].each do |rb| STDERR.puts "Requiring: #{rb}" require rb end end end |
.pages(task, form) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/sibyl/base.rb', line 79 def self.pages(task, form) filesystem_bag = {} dir = Rails.root.join("app", "sibyl", task, form) json_file = dir.to_s.gsub(/$/, ".json") STDERR.puts "Reading: #{json_file}" begin filesystem_bag = JSON.parse(File.read(json_file)) rescue Exception => e STDERR.puts("Exception: #{e}: #{e.backtrace}") Dir[dir.join("*")].each do |form| name = form.split(/\//).last unless filesystem_bag.has_key? name filesystem_bag[name] = {} end img = Magick::Image.ping( form ).first filesystem_bag[name]['width'] = img.columns filesystem_bag[name]['height'] = img.rows end end return filesystem_bag end |
.tasks ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/sibyl/base.rb', line 15 def self.tasks tasks = [] Dir[Rails.root.join("app", "sibyl", "*").to_s].each do |file| if File.directory? file tasks.push(Pathname.new(file).basename) end end tasks end |