simonmenke-cbs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +26 -0
- data/README.txt +48 -0
- data/Rakefile +4 -0
- data/bin/cbs +15 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/lib/cbs.rb +252 -0
- data/lib/cbs/version.rb +9 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_cbs.rb +11 -0
- data/test/test_helper.rb +2 -0
- data/website/index.html +11 -0
- data/website/index.txt +81 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- metadata +94 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Simon Menke
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
bin/cbs
|
8
|
+
config/hoe.rb
|
9
|
+
config/requirements.rb
|
10
|
+
lib/cbs.rb
|
11
|
+
lib/cbs/version.rb
|
12
|
+
script/console
|
13
|
+
script/destroy
|
14
|
+
script/generate
|
15
|
+
script/txt2html
|
16
|
+
setup.rb
|
17
|
+
tasks/deployment.rake
|
18
|
+
tasks/environment.rake
|
19
|
+
tasks/website.rake
|
20
|
+
test/test_cbs.rb
|
21
|
+
test/test_helper.rb
|
22
|
+
website/index.html
|
23
|
+
website/index.txt
|
24
|
+
website/javascripts/rounded_corners_lite.inc.js
|
25
|
+
website/stylesheets/screen.css
|
26
|
+
website/template.html.erb
|
data/README.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= cbs
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
CBS (Cascading behavior sheets) is an extention to javascript to build behavioral javascript
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2008 Simon Menke
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/cbs
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created on 2008-10-15.
|
4
|
+
# Copyright (c) 2008. All rights reserved.
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
require 'cbs'
|
9
|
+
rescue LoadError
|
10
|
+
# no rubygems to load, so we fail silently
|
11
|
+
end
|
12
|
+
|
13
|
+
parser = CBS::Compiler.new($stdin)
|
14
|
+
parser.parse
|
15
|
+
puts parser.format
|
data/config/hoe.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'cbs/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Simon Menke' # can also be an array of Authors
|
4
|
+
EMAIL = "simon.menke@gmail.com"
|
5
|
+
DESCRIPTION = "CBS (Cascading behavior sheets) is an extention to javascript to build behavioral javascript"
|
6
|
+
GEM_NAME = 'cbs' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'cbs' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
# ['activesupport', '>= 1.3.1']
|
12
|
+
] # An array of rubygem dependencies [name, version]
|
13
|
+
|
14
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
15
|
+
@config = nil
|
16
|
+
RUBYFORGE_USERNAME = "unknown"
|
17
|
+
def rubyforge_username
|
18
|
+
unless @config
|
19
|
+
begin
|
20
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
21
|
+
rescue
|
22
|
+
puts <<-EOS
|
23
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
24
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
25
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
26
|
+
EOS
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
REV = nil
|
35
|
+
# UNCOMMENT IF REQUIRED:
|
36
|
+
# REV = YAML.load(`svn info`)['Revision']
|
37
|
+
VERS = CBS::VERSION::STRING + (REV ? ".#{REV}" : "")
|
38
|
+
RDOC_OPTS = ['--quiet', '--title', 'cbs documentation',
|
39
|
+
"--opname", "index.html",
|
40
|
+
"--line-numbers",
|
41
|
+
"--main", "README",
|
42
|
+
"--inline-source"]
|
43
|
+
|
44
|
+
class Hoe
|
45
|
+
def extra_deps
|
46
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
47
|
+
@extra_deps
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generate all the Rake tasks
|
52
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
53
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
54
|
+
p.developer(AUTHOR, EMAIL)
|
55
|
+
p.description = DESCRIPTION
|
56
|
+
p.summary = DESCRIPTION
|
57
|
+
p.url = HOMEPATH
|
58
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
59
|
+
p.test_globs = ["test/**/test_*.rb"]
|
60
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
61
|
+
|
62
|
+
# == Optional
|
63
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
64
|
+
#p.extra_deps = EXTRA_DEPENDENCIES
|
65
|
+
|
66
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
67
|
+
end
|
68
|
+
|
69
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
70
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
71
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
72
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
73
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
data/lib/cbs.rb
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require "stringio"
|
5
|
+
|
6
|
+
module CBS
|
7
|
+
class Compiler
|
8
|
+
|
9
|
+
attr_reader :bindings
|
10
|
+
|
11
|
+
def initialize(io)
|
12
|
+
io = StringIO.new(io) if io.is_a? String
|
13
|
+
@io = io
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse
|
17
|
+
@selectors = Array.new
|
18
|
+
@bindings = Array.new
|
19
|
+
@classes = Array.new
|
20
|
+
|
21
|
+
selector = ''
|
22
|
+
while (char = @io.getc)
|
23
|
+
case char
|
24
|
+
when ?,
|
25
|
+
@selectors << selector.strip
|
26
|
+
selector = ''
|
27
|
+
when ?{
|
28
|
+
@selectors << selector.strip
|
29
|
+
selector = ''
|
30
|
+
|
31
|
+
@bindings << BlockBinding.new(@selectors, parseBlock(?}, 1, "{"))
|
32
|
+
|
33
|
+
@selectors = Array.new
|
34
|
+
when ?%
|
35
|
+
@selectors << selector.strip
|
36
|
+
selector = ''
|
37
|
+
|
38
|
+
@bindings << ObjectBinding.new(@selectors, parseBlock(?;, 0).sub(/\s*;$/, ''))
|
39
|
+
|
40
|
+
@selectors = Array.new
|
41
|
+
when ?@
|
42
|
+
|
43
|
+
if match('behavior')
|
44
|
+
@classes << parseClass('Behavior', 'create', false)
|
45
|
+
elsif match('class')
|
46
|
+
@classes << parseClass('Class', 'create', false)
|
47
|
+
elsif match('extention')
|
48
|
+
@classes << parseClass('_empty_', 'addMethods', true)
|
49
|
+
end
|
50
|
+
|
51
|
+
else
|
52
|
+
selector << char
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def parseClass(metaclass, initializer, switchNames)
|
58
|
+
name = readUntil(':{').strip
|
59
|
+
superclass = nil
|
60
|
+
functions = nil
|
61
|
+
char = @io.getc
|
62
|
+
if char == ?:
|
63
|
+
superclass = readUntil('{').strip
|
64
|
+
char = @io.getc
|
65
|
+
end
|
66
|
+
if char == ?{
|
67
|
+
functions = parseClassBlock
|
68
|
+
end
|
69
|
+
if switchNames
|
70
|
+
metaclass = name
|
71
|
+
superclass = nil
|
72
|
+
name = nil
|
73
|
+
end
|
74
|
+
Container.new(name, superclass, metaclass, initializer, functions)
|
75
|
+
end
|
76
|
+
|
77
|
+
def parseClassBlock
|
78
|
+
eob = false
|
79
|
+
functions = []
|
80
|
+
until eob
|
81
|
+
readUntil('}\':abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$')
|
82
|
+
case (char = @io.getc)
|
83
|
+
when nil then eob = true
|
84
|
+
when ?} then eob = true
|
85
|
+
else
|
86
|
+
functions << parseFunction("%c" % char)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
return functions
|
90
|
+
end
|
91
|
+
|
92
|
+
def parseFunction(name)
|
93
|
+
name += readUntil('{(').strip
|
94
|
+
arguments = ''
|
95
|
+
block = nil
|
96
|
+
char = @io.getc
|
97
|
+
if char == ?(
|
98
|
+
arguments += '('
|
99
|
+
arguments += readUntil(')')
|
100
|
+
arguments += @io.read(1)
|
101
|
+
readUntil('{')
|
102
|
+
char = @io.getc
|
103
|
+
else
|
104
|
+
arguments = '()'
|
105
|
+
end
|
106
|
+
if char == ?{
|
107
|
+
block = parseBlock(?}, 1, '{')
|
108
|
+
end
|
109
|
+
Function.new(name, arguments, block)
|
110
|
+
end
|
111
|
+
|
112
|
+
def parseBlock(terminator, level, code='')
|
113
|
+
eob = false
|
114
|
+
while (!eob) and (char = @io.getc)
|
115
|
+
case char
|
116
|
+
when ?'
|
117
|
+
code << parseString(?', "'")
|
118
|
+
when ?"
|
119
|
+
code << parseString(?", '"')
|
120
|
+
when ?{
|
121
|
+
level += 1
|
122
|
+
code << char
|
123
|
+
when ?}
|
124
|
+
level -= 1
|
125
|
+
code << char
|
126
|
+
else
|
127
|
+
code << char
|
128
|
+
end
|
129
|
+
eob = true if char == terminator and level == 0
|
130
|
+
end
|
131
|
+
code.strip.gsub(/\n/, "\n ")
|
132
|
+
end
|
133
|
+
|
134
|
+
def parseString(terminator, string)
|
135
|
+
eob = false
|
136
|
+
while (!eob) and (char = @io.getc)
|
137
|
+
case char
|
138
|
+
when ?\\
|
139
|
+
string << @io.getc
|
140
|
+
else
|
141
|
+
string << char
|
142
|
+
end
|
143
|
+
eob = true if char == terminator
|
144
|
+
end
|
145
|
+
string
|
146
|
+
end
|
147
|
+
|
148
|
+
def readUntil(delimiters)
|
149
|
+
string = ''
|
150
|
+
while char = @io.getc
|
151
|
+
if delimiters.include? char
|
152
|
+
@io.pos = @io.pos - 1
|
153
|
+
return string
|
154
|
+
end
|
155
|
+
string << char
|
156
|
+
end
|
157
|
+
string
|
158
|
+
end
|
159
|
+
|
160
|
+
def match(string)
|
161
|
+
pos = @io.pos
|
162
|
+
return true if @io.read(string.length) == string
|
163
|
+
@io.pos = pos
|
164
|
+
return false
|
165
|
+
end
|
166
|
+
|
167
|
+
def format
|
168
|
+
code = ""
|
169
|
+
code << @classes.inject('') do |c, klass|
|
170
|
+
c << klass.format
|
171
|
+
c
|
172
|
+
end
|
173
|
+
code << "\n"
|
174
|
+
code << "Event.addBehavior({\n"
|
175
|
+
code << @bindings.inject('') do |c, binding|
|
176
|
+
c << binding.format
|
177
|
+
c << ",\n" unless @bindings.last === binding
|
178
|
+
c
|
179
|
+
end
|
180
|
+
code << "\n});\n"
|
181
|
+
code
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
class Container
|
187
|
+
attr_accessor :name, :superclass, :metaclass, :initializer, :functions
|
188
|
+
def initialize(name, superclass, metaclass, initializer, functions)
|
189
|
+
@name, @superclass, @metaclass, @initializer, @functions = name, superclass, metaclass, initializer, functions
|
190
|
+
end
|
191
|
+
def format
|
192
|
+
code = ''
|
193
|
+
code += name_for_code
|
194
|
+
code += "#{metaclass}.#{initializer}("
|
195
|
+
code += "#{superclass}, " unless superclass.nil?
|
196
|
+
code += '{'
|
197
|
+
code += functions.inject('') do |m, function|
|
198
|
+
m += function.format(m.empty?)
|
199
|
+
end
|
200
|
+
code += "\n});\n\n"
|
201
|
+
end
|
202
|
+
|
203
|
+
def name_for_code
|
204
|
+
return '' if name.nil?
|
205
|
+
if (@name || '').include? '.'
|
206
|
+
"#{@name} = "
|
207
|
+
else
|
208
|
+
"var #{@name} = "
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
class Function
|
214
|
+
attr_accessor :name, :arguments, :block
|
215
|
+
def initialize(name, arguments, block)
|
216
|
+
@name, @arguments, @block = name, arguments, block
|
217
|
+
end
|
218
|
+
def format(first)
|
219
|
+
code = ''
|
220
|
+
code += ',' unless first
|
221
|
+
code += "\n"
|
222
|
+
code += " #{name} : function#{arguments}#{block.gsub("\n ", "\n")}"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
class Binding
|
227
|
+
attr_accessor :selectors, :code
|
228
|
+
def initialize(selectors, code)
|
229
|
+
@selectors, @code = selectors, code
|
230
|
+
end
|
231
|
+
def format
|
232
|
+
@selectors.inject('') do |code, selector|
|
233
|
+
code << format_with(selector)
|
234
|
+
code << ",\n" unless @selectors.last === selector
|
235
|
+
code
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
class BlockBinding < Binding
|
241
|
+
def format_with(selector)
|
242
|
+
" '#{selector.gsub("'", "\\'")}' : function(event)#{code}"
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
class ObjectBinding < Binding
|
247
|
+
def format_with(selector)
|
248
|
+
" '#{selector.gsub("'", "\\'")}' : #{code}"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|