lustr-core 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +20 -0
- data/README.txt +8 -0
- data/Rakefile +93 -0
- data/lib/lustr.rb +17 -0
- data/lib/lustr/blank_slate.rb +33 -0
- data/lib/lustr/builder.rb +117 -0
- data/lib/lustr/controller.rb +29 -0
- data/lib/lustr/defaults.rb +67 -0
- data/lib/lustr/dsl.rb +52 -0
- data/lib/lustr/engine.rb +59 -0
- data/lib/lustr/eval_context.rb +45 -0
- data/lib/lustr/gadget.rb +103 -0
- data/lib/lustr/generator.rb +81 -0
- data/lib/lustr/parse_context.rb +58 -0
- data/lib/lustr/runtime.rb +41 -0
- data/lib/lustr/version.rb +24 -0
- data/lib/lustr/widget.rb +103 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- metadata +73 -0
data/lib/lustr/engine.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of Lustr (http://rubyforge.org/projects/lustr).
|
3
|
+
|
4
|
+
Copyright (c) 2007 Mark L. Murphy.
|
5
|
+
|
6
|
+
Lustr is free software; you can redistribute it and/or modify it under the
|
7
|
+
terms of the GNU General Public License as published by the Free Software
|
8
|
+
Foundation; either version 2 of the License.
|
9
|
+
|
10
|
+
Lustr is distributed in the hope that it will be useful, but WITHOUT ANY
|
11
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
13
|
+
details. This file is included in the Ruby gem as License.txt.
|
14
|
+
=end
|
15
|
+
|
16
|
+
module Lustr
|
17
|
+
def self.declare(builder)
|
18
|
+
add_dsl_handler builder.widget_type, builder
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.defaults(sym)
|
22
|
+
Lustr::Defaults.send(sym)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.add_dsl_handler(sym, builder)
|
26
|
+
@builders ||= {}
|
27
|
+
@builders[sym]=builder
|
28
|
+
builder.type=sym if builder.respond_to?(:type=)
|
29
|
+
DSL.add_dsl_method sym
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_builder_klass(sym)
|
33
|
+
return @builders[sym]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.run
|
37
|
+
require ARGV[1]
|
38
|
+
|
39
|
+
self.execute(ARGV[0])
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.execute(script)
|
43
|
+
results=ParseContext.new
|
44
|
+
runtime=Runtime.new
|
45
|
+
dsl=DSL.new(results, runtime)
|
46
|
+
dsl.involve(script)
|
47
|
+
runtime.show(results)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.generate(options)
|
51
|
+
results=ParseContext.new
|
52
|
+
generator_klass=options[:generator]
|
53
|
+
generator=generator_klass.new(options)
|
54
|
+
dsl=DSL.new(results, generator)
|
55
|
+
dsl.involve(options[:script])
|
56
|
+
generator.generate(results)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of Lustr (http://rubyforge.org/projects/lustr).
|
3
|
+
|
4
|
+
Copyright (c) 2007 Mark L. Murphy.
|
5
|
+
|
6
|
+
Lustr is free software; you can redistribute it and/or modify it under the
|
7
|
+
terms of the GNU General Public License as published by the Free Software
|
8
|
+
Foundation; either version 2 of the License.
|
9
|
+
|
10
|
+
Lustr is distributed in the hope that it will be useful, but WITHOUT ANY
|
11
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
13
|
+
details. This file is included in the Ruby gem as License.txt.
|
14
|
+
=end
|
15
|
+
|
16
|
+
module Lustr
|
17
|
+
class EvalContext
|
18
|
+
def initialize
|
19
|
+
@gadget_stack=[]
|
20
|
+
end
|
21
|
+
|
22
|
+
def current_gadget
|
23
|
+
@gadget_stack.last
|
24
|
+
end
|
25
|
+
|
26
|
+
def for_gadget(gadget, callable)
|
27
|
+
@gadget_stack.push gadget
|
28
|
+
|
29
|
+
begin
|
30
|
+
callable.call
|
31
|
+
ensure
|
32
|
+
@gadget_stack.pop if @gadget_stack.size>1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def init_gadget(gadget, builder)
|
37
|
+
# mostly for subclasses
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_runtime?
|
41
|
+
false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
data/lib/lustr/gadget.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of Lustr (http://rubyforge.org/projects/lustr).
|
3
|
+
|
4
|
+
Copyright (c) 2007 Mark L. Murphy.
|
5
|
+
|
6
|
+
Lustr is free software; you can redistribute it and/or modify it under the
|
7
|
+
terms of the GNU General Public License as published by the Free Software
|
8
|
+
Foundation; either version 2 of the License.
|
9
|
+
|
10
|
+
Lustr is distributed in the hope that it will be useful, but WITHOUT ANY
|
11
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
13
|
+
details. This file is included in the Ruby gem as License.txt.
|
14
|
+
=end
|
15
|
+
|
16
|
+
require File.join(File.dirname(__FILE__), 'widget')
|
17
|
+
|
18
|
+
module Lustr
|
19
|
+
class Gadget < BlankSlate
|
20
|
+
include WidgetBase
|
21
|
+
|
22
|
+
attr_reader :widgets, :parent_widget, :builder
|
23
|
+
attr_reader :controller
|
24
|
+
|
25
|
+
def initialize(builder, parent_widget=nil, ctlr=NullController, options={})
|
26
|
+
@builder=builder
|
27
|
+
@widgets={}
|
28
|
+
@parent_widget=parent_widget
|
29
|
+
self.controller=ctlr
|
30
|
+
end
|
31
|
+
|
32
|
+
def controller=(thing)
|
33
|
+
@controller=(thing ? thing : NullController.new)
|
34
|
+
@controller=thing.new if thing.kind_of?(Class)
|
35
|
+
controller.gadget=self if controller
|
36
|
+
end
|
37
|
+
|
38
|
+
def resolve
|
39
|
+
return children[0].resolve if children.size>0
|
40
|
+
return super
|
41
|
+
end
|
42
|
+
|
43
|
+
def resolve_parent
|
44
|
+
return parent_widget
|
45
|
+
end
|
46
|
+
|
47
|
+
def show
|
48
|
+
children.each do |child|
|
49
|
+
child.show
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def generate(ctxt)
|
54
|
+
if parent_widget
|
55
|
+
contents(ctxt)
|
56
|
+
else
|
57
|
+
children.each do |child|
|
58
|
+
child.generate(ctxt)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def contents(ctxt)
|
64
|
+
ctxt.build_gadget_ref(self)
|
65
|
+
end
|
66
|
+
|
67
|
+
def method_missing(sym, *args)
|
68
|
+
result=widgets[sym.to_s]
|
69
|
+
|
70
|
+
return result if result
|
71
|
+
return super
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class GadgetBuilder < BuilderBase
|
76
|
+
attr_accessor :controller
|
77
|
+
|
78
|
+
def initialize(options={})
|
79
|
+
super(nil, options)
|
80
|
+
@controller=options[:controller]
|
81
|
+
end
|
82
|
+
|
83
|
+
def dup_from(options)
|
84
|
+
myself=self.dup
|
85
|
+
myself.options=options
|
86
|
+
myself.controller=controller
|
87
|
+
|
88
|
+
return myself
|
89
|
+
end
|
90
|
+
|
91
|
+
def build_all(eval_context, parent_widget=nil)
|
92
|
+
gadget=super
|
93
|
+
eval_context.init_gadget gadget, self
|
94
|
+
|
95
|
+
return gadget
|
96
|
+
end
|
97
|
+
|
98
|
+
def build(parent_widget)
|
99
|
+
return Gadget.new(self, parent_widget, controller, options)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of Lustr (http://rubyforge.org/projects/lustr).
|
3
|
+
|
4
|
+
Copyright (c) 2007 Mark L. Murphy.
|
5
|
+
|
6
|
+
Lustr is free software; you can redistribute it and/or modify it under the
|
7
|
+
terms of the GNU General Public License as published by the Free Software
|
8
|
+
Foundation; either version 2 of the License.
|
9
|
+
|
10
|
+
Lustr is distributed in the hope that it will be useful, but WITHOUT ANY
|
11
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
13
|
+
details. This file is included in the Ruby gem as License.txt.
|
14
|
+
=end
|
15
|
+
|
16
|
+
module Lustr
|
17
|
+
class Generator < EvalContext
|
18
|
+
attr_reader :options, :parse_context
|
19
|
+
|
20
|
+
def initialize(options)
|
21
|
+
super()
|
22
|
+
@options=options
|
23
|
+
end
|
24
|
+
|
25
|
+
def generate(parse_context)
|
26
|
+
@parse_context=parse_context
|
27
|
+
|
28
|
+
parse_context.gadget_builders.each_pair do |name, builder|
|
29
|
+
if name
|
30
|
+
base=name
|
31
|
+
dir=options[:gadget_dir] || options[:dir]
|
32
|
+
ext=options[:gadget_ext] || options[:extension]
|
33
|
+
ctxt=create_gadget_context(base)
|
34
|
+
else
|
35
|
+
base=options[:default_name] || 'application'
|
36
|
+
dir=options[:dir]
|
37
|
+
ext=options[:extension]
|
38
|
+
ctxt=create_context(base)
|
39
|
+
end
|
40
|
+
|
41
|
+
builder.build_all(self).generate(ctxt)
|
42
|
+
generate_builder(builder, dir, base, ext, options, ctxt)
|
43
|
+
end
|
44
|
+
|
45
|
+
generate_extra_files(options[:dir])
|
46
|
+
end
|
47
|
+
|
48
|
+
def generate_builder(builder, dir, base, ext, options, ctxt)
|
49
|
+
FileUtils.mkdir_p(dir)
|
50
|
+
path=File::join(dir, base+ext)
|
51
|
+
|
52
|
+
File.open(path, "w") do |aFile|
|
53
|
+
aFile.puts ctxt.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
if options[:script_extension]
|
57
|
+
path=File::join(dir, '_'+base+options[:script_extension])
|
58
|
+
|
59
|
+
if !File::exists?(path)
|
60
|
+
File.open(path, "w") do |aFile|
|
61
|
+
aFile.puts ""
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_context(name)
|
68
|
+
# for overridding in subclasses, required
|
69
|
+
raise Exception('Lustr::Generator#create_context must be overridden!')
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_gadget_context(name)
|
73
|
+
return create_context(name) # override if gadgets need separate context
|
74
|
+
end
|
75
|
+
|
76
|
+
def generate_extra_files(dir)
|
77
|
+
# for overridding in subclasses, optional
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of Lustr (http://rubyforge.org/projects/lustr).
|
3
|
+
|
4
|
+
Copyright (c) 2007 Mark L. Murphy.
|
5
|
+
|
6
|
+
Lustr is free software; you can redistribute it and/or modify it under the
|
7
|
+
terms of the GNU General Public License as published by the Free Software
|
8
|
+
Foundation; either version 2 of the License.
|
9
|
+
|
10
|
+
Lustr is distributed in the hope that it will be useful, but WITHOUT ANY
|
11
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
13
|
+
details. This file is included in the Ruby gem as License.txt.
|
14
|
+
=end
|
15
|
+
|
16
|
+
module Lustr
|
17
|
+
class ParseContext
|
18
|
+
attr_reader :gadget_builders
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@gadget_builders={}
|
22
|
+
@builder_stack=[]
|
23
|
+
builder=GadgetBuilder.new
|
24
|
+
gadget_builders[nil]=builder
|
25
|
+
@builder_stack.push builder
|
26
|
+
end
|
27
|
+
|
28
|
+
def current_builder
|
29
|
+
@builder_stack.last
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_builder(name, options)
|
33
|
+
current=current_builder
|
34
|
+
builder_klass=Lustr.get_builder_klass(name)
|
35
|
+
|
36
|
+
if builder_klass.kind_of?(Class)
|
37
|
+
child=builder_klass.new(options)
|
38
|
+
else
|
39
|
+
child=builder_klass.dup_from(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
current << child
|
43
|
+
attach_builder(child) { yield if block_given? }
|
44
|
+
end
|
45
|
+
|
46
|
+
def attach_builder(builder, name=nil)
|
47
|
+
@builder_stack.push builder
|
48
|
+
gadget_builders[name]=builder if name && builder.kind_of?(GadgetBuilder)
|
49
|
+
yield if block_given?
|
50
|
+
@builder_stack.pop
|
51
|
+
end
|
52
|
+
|
53
|
+
def handle_event(name, callable)
|
54
|
+
current_builder.event_handlers[name]=callable
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of Lustr (http://rubyforge.org/projects/lustr).
|
3
|
+
|
4
|
+
Copyright (c) 2007 Mark L. Murphy.
|
5
|
+
|
6
|
+
Lustr is free software; you can redistribute it and/or modify it under the
|
7
|
+
terms of the GNU General Public License as published by the Free Software
|
8
|
+
Foundation; either version 2 of the License.
|
9
|
+
|
10
|
+
Lustr is distributed in the hope that it will be useful, but WITHOUT ANY
|
11
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
13
|
+
details. This file is included in the Ruby gem as License.txt.
|
14
|
+
=end
|
15
|
+
|
16
|
+
module Lustr
|
17
|
+
class Runtime < EvalContext
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def show(parse_context)
|
23
|
+
root=parse_context.gadget_builders[nil].build_all(self)
|
24
|
+
|
25
|
+
root.show
|
26
|
+
end
|
27
|
+
|
28
|
+
def init_gadget(gadget, builder)
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def attach_controller()
|
33
|
+
# mostly for subclasses
|
34
|
+
end
|
35
|
+
|
36
|
+
def is_runtime?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of Lustr (http://rubyforge.org/projects/lustr).
|
3
|
+
|
4
|
+
Copyright (c) 2007 Mark L. Murphy.
|
5
|
+
|
6
|
+
Lustr is free software; you can redistribute it and/or modify it under the
|
7
|
+
terms of the GNU General Public License as published by the Free Software
|
8
|
+
Foundation; either version 2 of the License.
|
9
|
+
|
10
|
+
Lustr is distributed in the hope that it will be useful, but WITHOUT ANY
|
11
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
13
|
+
details. This file is included in the Ruby gem as License.txt.
|
14
|
+
=end
|
15
|
+
|
16
|
+
module Lustr #:nodoc:
|
17
|
+
module VERSION #:nodoc:
|
18
|
+
MAJOR = 0
|
19
|
+
MINOR = 1
|
20
|
+
TINY = 0
|
21
|
+
|
22
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
23
|
+
end
|
24
|
+
end
|
data/lib/lustr/widget.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of Lustr (http://rubyforge.org/projects/lustr).
|
3
|
+
|
4
|
+
Copyright (c) 2007 Mark L. Murphy.
|
5
|
+
|
6
|
+
Lustr is free software; you can redistribute it and/or modify it under the
|
7
|
+
terms of the GNU General Public License as published by the Free Software
|
8
|
+
Foundation; either version 2 of the License.
|
9
|
+
|
10
|
+
Lustr is distributed in the hope that it will be useful, but WITHOUT ANY
|
11
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
13
|
+
details. This file is included in the Ruby gem as License.txt.
|
14
|
+
=end
|
15
|
+
|
16
|
+
require 'erb'
|
17
|
+
require 'rubygems'
|
18
|
+
require 'builder'
|
19
|
+
|
20
|
+
module Lustr
|
21
|
+
module WidgetBase
|
22
|
+
attr_accessor :name, :eval_context, :gadget, :label, :parent
|
23
|
+
attr_reader :options
|
24
|
+
|
25
|
+
def children
|
26
|
+
@children||=[]
|
27
|
+
@children
|
28
|
+
end
|
29
|
+
|
30
|
+
def <<(child)
|
31
|
+
_add(child)
|
32
|
+
end
|
33
|
+
|
34
|
+
def _add(child)
|
35
|
+
children << child
|
36
|
+
child.parent=self
|
37
|
+
end
|
38
|
+
|
39
|
+
def resolve
|
40
|
+
return self
|
41
|
+
end
|
42
|
+
|
43
|
+
def resolve_parent
|
44
|
+
return self
|
45
|
+
end
|
46
|
+
|
47
|
+
def init_options(options)
|
48
|
+
@options=options
|
49
|
+
end
|
50
|
+
|
51
|
+
def option(name)
|
52
|
+
return options[name]
|
53
|
+
end
|
54
|
+
|
55
|
+
def controller=(thing)
|
56
|
+
gadget.controller=thing
|
57
|
+
end
|
58
|
+
|
59
|
+
def raise_event(expr, event=nil)
|
60
|
+
if expr
|
61
|
+
if expr.kind_of?(Proc)
|
62
|
+
expr.call(event, gadget)
|
63
|
+
elsif expr.kind_of?(Symbol)
|
64
|
+
gadget.controller.send(expr, event) if gadget.controller
|
65
|
+
else
|
66
|
+
gadget.controller.instance_eval(expr) if gadget.controller
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_s
|
72
|
+
return label if label
|
73
|
+
return super
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class XmlBasedWidget
|
78
|
+
include WidgetBase
|
79
|
+
end
|
80
|
+
|
81
|
+
class TemplatedWidget
|
82
|
+
include WidgetBase
|
83
|
+
|
84
|
+
def generate(ctxt)
|
85
|
+
ctxt << contents(ctxt)
|
86
|
+
end
|
87
|
+
|
88
|
+
def contents(ctxt)
|
89
|
+
ERB.new(template).result(binding)
|
90
|
+
end
|
91
|
+
|
92
|
+
def children_contents(ctxt)
|
93
|
+
result=''
|
94
|
+
|
95
|
+
children.each do |child|
|
96
|
+
result+=child.contents(ctxt)+"\n" if child.respond_to?(:contents)
|
97
|
+
end
|
98
|
+
|
99
|
+
return(result)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|