Module: Pangrid
- Defined in:
- lib/pangrid/plugins/qxw.rb,
lib/pangrid.rb,
lib/pangrid/xw.rb,
lib/pangrid/utils.rb,
lib/pangrid/plugin.rb,
lib/pangrid/version.rb,
lib/pangrid/plugins/csv.rb,
lib/pangrid/plugins/text.rb,
lib/pangrid/plugins/excel.rb,
lib/pangrid/plugins/reddit.rb,
lib/pangrid/frontend/webrick.rb,
lib/pangrid/plugins/acrosslite.rb
Overview
Markup used by crosswords.reddit.com
Defined Under Namespace
Modules: AcrossLiteUtils, PluginUtils, RedditWriter Classes: AcrossLiteBinary, AcrossLiteText, CSV, Cell, Checksum, ExcelXSLX, Plugin, PluginDependencyError, PuzzleFormatError, Qxw, Rebus, RedditBlank, RedditFilled, Servlet, Text, XWord
Constant Summary collapse
- VERSION =
'0.3.1'
- QXW_GRID_ERROR =
"Could not read grid from .qxw file"
- TEMPLATE_DIR =
File.dirname(File.(__FILE__)) + '/../data'
- TEMPLATE =
TEMPLATE_DIR + '/webform.html'
- GRID_CHARS =
{:black => '.', :null => '?'}
- FILL_CHARS =
{:black => '.', :null => '-'}
Class Method Summary collapse
-
.require_for_plugin(name, gems) ⇒ Object
Load all the gem dependencies of a plugin.
- .run(opts) ⇒ Object
- .run_command_line ⇒ Object
- .run_webserver(port) ⇒ Object
Class Method Details
.require_for_plugin(name, gems) ⇒ Object
Load all the gem dependencies of a plugin
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pangrid/plugin.rb', line 15 def self.require_for_plugin(name, gems) missing = [] gems.each do |gem| begin require gem rescue LoadError => e # If requiring a gem raises something other than LoadError let it # propagate upwards. missing << gem end end if !missing.empty? raise PluginDependencyError.new(name, missing) end end |
.run(opts) ⇒ Object
33 34 35 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 |
# File 'lib/pangrid.rb', line 33 def self.run(opts) Plugin.load_all if opts[:list] Plugin.list_all return end # run the converter # from = Plugin.get(opts[:from]) to = Plugin.get(opts[:to]) if !from or !from.method_defined? :read $stderr.puts "No reader for #{opts[:from]}" return end if !to or !to.method_defined? :write $stderr.puts "No writer for #{opts[:to]}" return end if !File.exist? opts[:in] $stderr.puts "Cannot find file #{opts[:in]}" return end reader = from.new writer = to.new input = IO.read(opts[:in]) output = writer.write(reader.read(input)) File.open(opts[:out], "w") do |f| f.print output end end |
.run_command_line ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pangrid.rb', line 8 def self.run_command_line # command line options p = Trollop::Parser.new do version "pangrid #{VERSION}" opt :from, "Format to convert from", :type => :string opt :to, "Format to convert to", :type => :string opt :in, "Input file", :type => :string opt :out, "Output file", :type => :string opt :list, "List available format plugins" opt :web, "Launch webserver" end Trollop::with_standard_exception_handling p do opts = p.parse ARGV if opts[:web] run_webserver 1234 elsif opts[:list] || [:from, :to, :in, :out].all? {|k| opts[k]} run opts else p.educate end end end |
.run_webserver(port) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pangrid/frontend/webrick.rb', line 37 def self.run_webserver(port) puts "-------------------------------------------" puts "Open your web browser and load" puts " http://localhost:#{port}" puts "-------------------------------------------" Plugin.load_all logfile = File.open('pangrid-webrick-access.log', 'a') logfile.sync = true log = [ [logfile, WEBrick::AccessLog::COMMON_LOG_FORMAT] ] server = WEBrick::HTTPServer.new(:Port => port, :AccessLog => log) server.mount "/", Servlet trap("INT") { server.shutdown } server.start end |