Module: Wee

Defined in:
lib/wee.rb,
lib/wee/task.rb,
lib/wee/state.rb,
lib/wee/dialog.rb,
lib/wee/request.rb,
lib/wee/session.rb,
lib/wee/callback.rb,
lib/wee/renderer.rb,
lib/wee/response.rb,
lib/wee/component.rb,
lib/wee/lru_cache.rb,
lib/wee/presenter.rb,
lib/wee/decoration.rb,
lib/wee/application.rb,
lib/wee/html_canvas.rb,
lib/wee/html_writer.rb,
lib/wee/html_brushes.rb,
lib/wee/id_generator.rb,
lib/wee/html_document.rb,
lib/wee/root_component.rb,
lib/wee/external_resource.rb

Defined Under Namespace

Modules: CallbackMixin, DupReplaceSnapshotMixin, ObjectSnapshotMixin, StructSnapshotMixin Classes: AnswerDecoration, Application, BlockComponent, Brush, CallbackRegistry, Callbacks, Component, ConfirmDialog, Decoration, Delegate, Dialog, ErrorResponse, ExternalResource, FormDecoration, FormDialog, GenericResponse, HelloWorld, HtmlCanvas, HtmlDocument, HtmlWriter, IdGenerator, InformDialog, JQuery, LRUCache, MessageDialog, NotFoundResponse, OidDecoration, PageDecoration, Presenter, RedirectResponse, RefreshResponse, Renderer, Request, Response, RightJS, RootComponent, Session, SingleSelectionDialog, State, StyleDecoration, Task, TextAreaDialog, TextInputDialog, WrapperDecoration

Constant Summary collapse

Version =
"2.2.0"

Class Method Summary collapse

Class Method Details

.run(component_class = nil, params = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


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
# File 'lib/wee.rb', line 39

def Wee.run(component_class=nil, params=nil, &block)
  raise ArgumentError if component_class and block

  params ||= Hash.new
  params[:mount_path] ||= '/'
  params[:port] ||= 2000
  params[:public_path] ||= nil
  params[:additional_builder_procs] ||= []
  params[:use_continuations] ||= true
  params[:print_message] ||= false
  params[:autoreload] ||= false

  if component_class <= Wee::RootComponent
    component_class.external_resources.each do |ext_res|  
      params[:additional_builder_procs] << proc {|builder| ext_res.install(builder)}
    end
  end

  raise ArgumentError if params[:use_continuations] and block 

  unless block
    block ||= if params[:use_continuations]
      proc { Wee::Session.new(component_class.instanciate,
                 Wee::Session::ThreadSerializer.new) }
    else
      proc { Wee::Session.new(component_class.instanciate) }
    end
  end

  app = Rack::Builder.app do
    map params[:mount_path] do
      a = Wee::Application.new(&block)

      if params[:auth_md5]
        a = Rack::Auth::Digest::MD5.new(a, &params[:auth_md5])
        a.realm = params[:auth_realm] || 'Wee App'
        a.opaque = params[:auth_md5_opaque] || Wee::IdGenerator::Secure.new.next
      end

      if params[:auth_basic]
        a = Rack::Auth::Basic.new(a, params[:auth_realm] || 'Wee App', &params[:auth_basic])
      end

      if params[:autoreload]
        if params[:autoreload].kind_of?(Integer)
          timer = Integer(params[:autoreload])
        else
          timer = 0
        end
        use Rack::Reloader, timer 
      end

      if params[:public_path]
        run Rack::Cascade.new([Rack::File.new(params[:public_path]), a])
      else
        run a
      end
    end
    params[:additional_builder_procs].each {|bproc| bproc.call(self)}
  end

  if params[:print_message]
    url = "http://localhost:#{params[:port]}#{params[:mount_path]}"
    io = params[:print_message].kind_of?(IO) ? params[:print_message] : STDERR
    io.puts
    io.puts "Open your browser at: #{url}"
    io.puts
  end

  Rack::Handler::WEBrick.run(app, :Port => params[:port])
end