rbml 0.0.5.9.2 → 0.0.5.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +3 -0
- data/bin/rbml +3 -2
- data/examples/cli/happycli.rbml +30 -8
- data/examples/doc/_partial.rbml +8 -1
- data/examples/doc/test.rbml +2 -0
- data/languages/cli/cli.rb +12 -14
- data/languages/doc/base.rb +0 -14
- data/languages/doc/xhtml.rb +9 -5
- data/lib/base.rb +3 -3
- data/lib/cli.rb +4 -6
- data/lib/cli_tools.rb +139 -0
- data/lib/cli_tools/array.rb +0 -0
- data/lib/cli_tools/string.rb +0 -0
- data/lib/extensions/primitives.rb +14 -3
- data/lib/extensions/string.rb +6 -1
- data/lib/processor.rb +26 -9
- data/lib/rbml.rb +2 -2
- metadata +6 -3
data/Manifest.txt
CHANGED
data/bin/rbml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
#$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
3
3
|
$template_dir = File.dirname(ARGV[0]) if ARGV[0]
|
4
4
|
|
5
5
|
require File.dirname(__FILE__)+'/../lib/rbml'
|
6
|
-
|
6
|
+
$script_extention = ARGV.first.gsub(/^.+\./, '')
|
7
|
+
::Rbml::Processor.run(ARGV.first)
|
data/examples/cli/happycli.rbml
CHANGED
@@ -1,16 +1,38 @@
|
|
1
|
-
cli :name=>"happycli", :prompt=>"
|
2
|
-
set :unknown_command do
|
3
|
-
|
1
|
+
cli :name=>"happycli", :prompt=>"^_^ " do
|
2
|
+
set :unknown_command do |args|
|
3
|
+
puts "unknown command"
|
4
4
|
end
|
5
5
|
|
6
|
-
set :
|
7
|
-
|
6
|
+
set :com do |args|
|
7
|
+
flag(:help => 'h'){
|
8
|
+
puts 'help docs for this command'
|
9
|
+
}
|
10
|
+
flag(:name => 'n'){ |value|
|
11
|
+
puts "the name you gave was #{value}"
|
12
|
+
}
|
13
|
+
key(:test){
|
14
|
+
puts 'good. the test option is running.'
|
15
|
+
}
|
16
|
+
key(:best){ puts 'great. now the best one is.' }
|
17
|
+
|
18
|
+
process args
|
19
|
+
|
20
|
+
# now have access to remaining arguments as follows:
|
21
|
+
puts "\nremaining individual arguments (after flags): #{remaining_arguments.inspect}"
|
22
|
+
puts "\njoined remaining arguments (after flags): #{remaining_argument}"
|
23
|
+
|
24
|
+
# and also the active keys and flags
|
25
|
+
puts "\nactive options: #{active_options}"
|
8
26
|
end
|
9
27
|
|
10
|
-
set :
|
11
|
-
|
28
|
+
set :clear do
|
29
|
+
system 'clear'
|
12
30
|
end
|
13
|
-
|
31
|
+
|
32
|
+
set :help do
|
33
|
+
puts "put helpdocs here"
|
34
|
+
end
|
35
|
+
|
14
36
|
set :quit do
|
15
37
|
exit
|
16
38
|
end
|
data/examples/doc/_partial.rbml
CHANGED
data/examples/doc/test.rbml
CHANGED
data/languages/cli/cli.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
|
2
|
+
require 'cli_tools'
|
3
|
+
|
1
4
|
module Rbml
|
2
5
|
module Language
|
3
6
|
module Cli
|
4
7
|
module Cli
|
8
|
+
include CliTools
|
9
|
+
include Flagger
|
10
|
+
|
5
11
|
DEFINITION = {"unknown_command" => lambda {puts "unknown command type 'help' for instructions"}}
|
6
12
|
|
7
13
|
def set(method, &proc)
|
@@ -10,24 +16,16 @@ module Rbml
|
|
10
16
|
end
|
11
17
|
|
12
18
|
def call(method, *args)
|
19
|
+
clear_arguments
|
13
20
|
begin
|
14
|
-
|
15
|
-
if args.length == 0 && mymethod.arity == -1
|
16
|
-
mymethod.call
|
17
|
-
elsif mymethod.arity.abs == args.length
|
18
|
-
mymethod.call(*args)
|
19
|
-
else
|
20
|
-
puts "bad syntax"
|
21
|
-
end
|
21
|
+
args.empty? ? DEFINITION.fetch(method)[nil] : DEFINITION.fetch(method)[args]
|
22
22
|
rescue
|
23
|
-
DEFINITION.fetch("unknown_command")
|
23
|
+
DEFINITION.fetch("unknown_command")[args]
|
24
|
+
ensure
|
25
|
+
puts "\n"
|
24
26
|
end
|
25
27
|
end
|
26
|
-
|
27
|
-
def cliprint(string)
|
28
|
-
string
|
29
|
-
end
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
33
|
-
end
|
31
|
+
end
|
data/languages/doc/base.rb
CHANGED
@@ -2,20 +2,6 @@ module Rbml
|
|
2
2
|
module Language
|
3
3
|
module Doc
|
4
4
|
module Base
|
5
|
-
def find_partial(str)
|
6
|
-
arr = str.split("/")
|
7
|
-
arr.last[0,0] = "_"
|
8
|
-
find_local_file(arr.join("/") + '.rbml')
|
9
|
-
end
|
10
|
-
|
11
|
-
def find_local_file(filename)
|
12
|
-
find_file($template_dir +'/' + filename)
|
13
|
-
end
|
14
|
-
|
15
|
-
def find_file(filename)
|
16
|
-
__instance_eval__ File.read(filename)
|
17
|
-
end
|
18
|
-
|
19
5
|
def print(doc)
|
20
6
|
puts doc
|
21
7
|
end
|
data/languages/doc/xhtml.rb
CHANGED
@@ -3,6 +3,13 @@ require 'redcloth'
|
|
3
3
|
require 'doc/xml'
|
4
4
|
require 'rexml/document'
|
5
5
|
|
6
|
+
|
7
|
+
module Inclusion
|
8
|
+
def include(file)
|
9
|
+
run_file [$template_dir, file.as_partial].join('/')+'.rbml'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
6
13
|
module Rbml
|
7
14
|
module Language
|
8
15
|
module Doc
|
@@ -10,7 +17,7 @@ module Rbml
|
|
10
17
|
include Xml
|
11
18
|
::Kernel.send(:undef_method, :p)
|
12
19
|
|
13
|
-
def tags; %w(body title head p div ul li html a br span)end
|
20
|
+
def tags; %w(body title head p div ul li html a br span h1 h2 h3 h4 h5 h6 strong img i u b pre kbd code cite strong em ins sup sub del table tr td th ol blockquote)end
|
14
21
|
|
15
22
|
def stylesheets *sheets
|
16
23
|
all_sheets = ''
|
@@ -38,14 +45,11 @@ module Rbml
|
|
38
45
|
def end_tag *options
|
39
46
|
"</html>"
|
40
47
|
end
|
41
|
-
|
42
|
-
def include(str)
|
43
|
-
find_partial(str)
|
44
|
-
end
|
45
48
|
|
46
49
|
def format(doc)
|
47
50
|
fdoc = REXML::Document.new doc.assemble_doc
|
48
51
|
fdoc.write doc.formatted_doc, 1
|
52
|
+
doc.formatted_doc
|
49
53
|
end
|
50
54
|
|
51
55
|
def textilize(str)
|
data/lib/base.rb
CHANGED
@@ -9,9 +9,9 @@ module Rbml
|
|
9
9
|
|
10
10
|
def instance_eval_each(code, &blk)
|
11
11
|
$breaker = BlockBreaker.new do |name, args, block|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
yield @dsl.__send__(name, *args, &block)
|
13
|
+
end
|
14
|
+
$breaker.__instance_eval__ &code
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/cli.rb
CHANGED
@@ -2,16 +2,14 @@ module Rbml
|
|
2
2
|
class Cli < Base
|
3
3
|
def self.render(language, options, &block)
|
4
4
|
d = Cli.new(language)
|
5
|
-
display = lambda
|
6
|
-
puts "#{result}\n" unless result.nil?
|
7
|
-
end
|
5
|
+
display = lambda { |result| result }
|
8
6
|
loop do
|
9
7
|
begin
|
10
8
|
printf options[:prompt]
|
11
|
-
d.instance_eval_each(block, &display)
|
9
|
+
d.instance_eval_each(block, &display)
|
12
10
|
obj = IO.new(0, "w+")
|
13
11
|
args = obj.gets.split
|
14
|
-
d.dsl.__send__("call", *args)
|
12
|
+
d.dsl.__send__("call", *args) unless args.empty?
|
15
13
|
rescue Interrupt
|
16
14
|
puts "\nExiting #{options[:name]}..."
|
17
15
|
break
|
@@ -19,4 +17,4 @@ module Rbml
|
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
22
|
-
end
|
20
|
+
end
|
data/lib/cli_tools.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
|
2
|
+
class String
|
3
|
+
def flag?; self[0,1]=='-' end
|
4
|
+
def shift; self.slice! 0,1 end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Array
|
8
|
+
def duplicate; *copy = *self.map{|a|a.dup} end
|
9
|
+
end
|
10
|
+
|
11
|
+
module CliTools
|
12
|
+
def request_value words=nil
|
13
|
+
printf words+' ' if words
|
14
|
+
$stdin.gets
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Flagger
|
19
|
+
def clear_arguments
|
20
|
+
@flags ={}
|
21
|
+
@active_keys = {}
|
22
|
+
@active_flags = {}
|
23
|
+
@potential_flags = {}
|
24
|
+
@associated_blocks = {}
|
25
|
+
@remaining_argument = []
|
26
|
+
@potential_keywords = []
|
27
|
+
end
|
28
|
+
|
29
|
+
def process(args=nil)
|
30
|
+
seperate_arguments_from(args) if args
|
31
|
+
process_command_line_input
|
32
|
+
end
|
33
|
+
def seperate_arguments_from(args)
|
34
|
+
args = args.duplicate
|
35
|
+
while !args.empty? and not args.first.flag?
|
36
|
+
if @potential_keywords.include?(args.first.to_sym)
|
37
|
+
@active_keys.merge! args.shift.to_sym => nil
|
38
|
+
else
|
39
|
+
@remaining_argument << args.shift
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@flags = args
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_command_line_input &blk
|
46
|
+
flags = parse_flags(@flags)
|
47
|
+
run_flags @active_keys
|
48
|
+
run_flags flags
|
49
|
+
end
|
50
|
+
|
51
|
+
def trip_flag which, with_value=nil
|
52
|
+
start_flag_checking
|
53
|
+
@active_flags.merge!({which => (with_value || true)})
|
54
|
+
end
|
55
|
+
|
56
|
+
def start_flag_checking
|
57
|
+
@active_flags ||= {}
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_flags(args)
|
61
|
+
start_flag_checking
|
62
|
+
while not args.empty?
|
63
|
+
flag_set = args.shift
|
64
|
+
flag_set.shift
|
65
|
+
unless flag_set.flag?
|
66
|
+
while not flag_set.empty?
|
67
|
+
@active_flags.merge!({flag_key_for(flag_set.shift) => (flag_set.empty? && args.first) ? (args.first.flag? or args.shift ) : true})
|
68
|
+
end
|
69
|
+
else
|
70
|
+
flag_set.shift
|
71
|
+
@active_flags.merge!({flag_key_for(flag_set) => (args.first ? (args.first.flag? or args.shift) : true) })
|
72
|
+
end
|
73
|
+
end
|
74
|
+
@active_flags
|
75
|
+
end
|
76
|
+
|
77
|
+
def flag_key_for(which)
|
78
|
+
return which.to_sym if @potential_flags.member? which.to_sym
|
79
|
+
try = @potential_flags.invert
|
80
|
+
return try[which] if try.member? which
|
81
|
+
return nil
|
82
|
+
end
|
83
|
+
|
84
|
+
def flag option, &blk
|
85
|
+
set_flag option
|
86
|
+
set_block option, blk
|
87
|
+
end
|
88
|
+
alias key flag
|
89
|
+
|
90
|
+
def flag_and_key option, &blk
|
91
|
+
flag option, &blk
|
92
|
+
option.each { |k, v| flag k, &blk }
|
93
|
+
end
|
94
|
+
|
95
|
+
def set_flag(option)
|
96
|
+
if option.respond_to? :merge!
|
97
|
+
@potential_flags.merge! option
|
98
|
+
else
|
99
|
+
@potential_keywords << option
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_block(option, blk=nil)
|
104
|
+
@associated_blocks||= {}
|
105
|
+
blk ||= lambda{}
|
106
|
+
tmp = {}
|
107
|
+
if option.kind_of? Symbol
|
108
|
+
tmp[option] = blk
|
109
|
+
else
|
110
|
+
option.each {|key, value| tmp[key] = blk}
|
111
|
+
end
|
112
|
+
@associated_blocks.merge! tmp
|
113
|
+
end
|
114
|
+
|
115
|
+
def run_flags(options)
|
116
|
+
options.each { |key, value|
|
117
|
+
@associated_blocks[key.to_sym][value] rescue help_docs
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
def help_docs
|
122
|
+
exit
|
123
|
+
end
|
124
|
+
|
125
|
+
def active_options
|
126
|
+
flags = @active_flags || {}
|
127
|
+
keys = @active_keys || {}
|
128
|
+
flags.merge keys
|
129
|
+
end
|
130
|
+
def remaining_arguments
|
131
|
+
@remaining_argument||[]
|
132
|
+
end
|
133
|
+
def remaining_argument
|
134
|
+
@remaining_argument.join(' ')
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
File without changes
|
File without changes
|
@@ -1,3 +1,13 @@
|
|
1
|
+
module Inclusion
|
2
|
+
def run_file(file)
|
3
|
+
__instance_eval__ ::Rbml::Processor.read(file)
|
4
|
+
end
|
5
|
+
|
6
|
+
def include(file)
|
7
|
+
run_file file+'.rbml'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
1
11
|
module Primitives
|
2
12
|
class BlankSlate #:nodoc:
|
3
13
|
alias :__instance_eval__ :instance_eval
|
@@ -15,6 +25,8 @@ module Primitives
|
|
15
25
|
end
|
16
26
|
|
17
27
|
class BlockBreaker < BlankSlate #:nodoc:
|
28
|
+
include Inclusion
|
29
|
+
|
18
30
|
def initialize(&block)
|
19
31
|
if block_given?
|
20
32
|
@handler = block
|
@@ -22,12 +34,11 @@ module Primitives
|
|
22
34
|
raise NoBlockGiven, "Must be a block to break!"
|
23
35
|
end
|
24
36
|
end
|
25
|
-
|
26
37
|
def method_missing(name, *args, &block)
|
27
|
-
@handler.call(name, args, block)
|
38
|
+
@handler.call(name, args, block)
|
28
39
|
end
|
29
40
|
end
|
30
41
|
|
31
42
|
class NoBlockGiven < StandardError #:nodoc:
|
32
43
|
end
|
33
|
-
end
|
44
|
+
end
|
data/lib/extensions/string.rb
CHANGED
data/lib/processor.rb
CHANGED
@@ -9,20 +9,37 @@ module Rbml
|
|
9
9
|
ROUTES.fetch(name)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
require "#{route_for(method_name.to_sym).downcase}/#{method_name}"
|
14
|
-
language = "Language::#{route_for(method_name.to_sym)}::#{method_name.camelize}".to_m
|
15
|
-
Rbml.const_get(route_for(method_name.to_sym)).render(language, options, &block)
|
16
|
-
end
|
12
|
+
def method_name; caller[0][/`([^']*)'/, 1]; end
|
17
13
|
|
18
|
-
|
19
|
-
|
14
|
+
def spawn(options, *args, &block)
|
15
|
+
language = if args.first.kind_of?(Hash) and args.first[:as_language]
|
16
|
+
args[:as_language]
|
17
|
+
else
|
18
|
+
method_name rescue $script_extention
|
19
|
+
end
|
20
|
+
language = load_language(language)
|
21
|
+
render(method_name, language, options, &block)
|
20
22
|
end
|
21
23
|
|
22
|
-
def method_name
|
24
|
+
def render(method_name, language, options, &block)
|
25
|
+
Rbml.const_get(route_for(method_name.to_sym)).render(language, options, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def load_language(language)
|
29
|
+
require "#{route_for(language.to_sym).downcase}/#{language}"
|
30
|
+
"Language::#{route_for(language.to_sym)}::#{language.camelize}".to_m
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.read(file)
|
34
|
+
File.read(file)
|
35
|
+
end
|
23
36
|
|
24
37
|
def self.run(argv)
|
25
|
-
new.instance_eval File.
|
38
|
+
new.instance_eval File.read(argv)
|
26
39
|
end
|
40
|
+
|
41
|
+
ROUTES.each_key do |k|
|
42
|
+
alias_method k, :spawn
|
43
|
+
end
|
27
44
|
end
|
28
45
|
end
|
data/lib/rbml.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
2
1
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)) + "/../languages")
|
2
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module Rbml
|
5
|
-
VERSION = '0.0.5.9.
|
5
|
+
VERSION = '0.0.5.9.3'
|
6
6
|
end
|
7
7
|
require 'extensions/kernel'
|
8
8
|
require 'extensions/primitives'
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rbml
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.5.9.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.0.5.9.3
|
7
|
+
date: 2007-05-01 00:00:00 -04:00
|
8
8
|
summary: Rbml is a dsl framework for writing other languages in ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -56,6 +56,9 @@ files:
|
|
56
56
|
- lib/processor.rb
|
57
57
|
- lib/rbml.rb
|
58
58
|
- lib/shell.rb
|
59
|
+
- lib/cli_tools.rb
|
60
|
+
- lib/cli_tools/array.rb
|
61
|
+
- lib/cli_tools/string.rb
|
59
62
|
- spec/doc_spec.rb
|
60
63
|
- spec/object_spec.rb
|
61
64
|
- spec/rbml_spec.rb
|
@@ -80,5 +83,5 @@ dependencies:
|
|
80
83
|
requirements:
|
81
84
|
- - ">="
|
82
85
|
- !ruby/object:Gem::Version
|
83
|
-
version: 1.
|
86
|
+
version: 1.2.0
|
84
87
|
version:
|