rbml 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.
@@ -0,0 +1,5 @@
1
+ == 0.0.1 / 2007-01-28
2
+
3
+ * Rbml is born
4
+ * There was much rejoicing
5
+
@@ -0,0 +1,21 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/rbmlout
6
+ languages/base.rb
7
+ languages/xhtml.rb
8
+ languages/xml.rb
9
+ lib/doc.rb
10
+ lib/extensions/kernel.rb
11
+ lib/extensions/string.rb
12
+ lib/processor.rb
13
+ lib/rbml.rb
14
+ spec/doc_spec.rb
15
+ spec/fixtures/_partial.rbml
16
+ spec/fixtures/sublist/_sublist.rbml
17
+ spec/fixtures/synopsis.rbml
18
+ spec/fixtures/test.rbml
19
+ spec/object_spec.rb
20
+ spec/rbml_spec.rb
21
+ spec/spec_helper.rb
@@ -0,0 +1,85 @@
1
+ rbmlhoe
2
+ by Jake Howerton, Evan Short
3
+ http://rbml.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ Rbml is a dsl framework for outputting other languages (currently supports Xhtml, XML)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * XML support is totally untested since we don't need it
12
+
13
+ == SYNOPSIS:
14
+ xhtml :doctype => {:type=>:xhtml, :version=>"1.0", :strict=>false} do
15
+ head do
16
+ title "Sample Site"
17
+ stylesheets :base, :links
18
+ #COMMENTS DONT GET EVAL'd
19
+ end
20
+
21
+ body do
22
+ textilize "*Header*"
23
+ div "this is our first html doc!"
24
+ p "its really awesome"
25
+ myvar = "withconcat"
26
+ p do
27
+ inline "dot operator #{myvar}"
28
+ span "nested span"
29
+ end
30
+ end
31
+ end
32
+
33
+ Outputs
34
+
35
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
36
+ <html>
37
+ <head>
38
+ <title>Sample Site</title>
39
+ <link href='/stylesheets/base.css' rel='stylesheet' type='text/css'/>
40
+ <link href='/stylesheets/links.css' rel='stylesheet' type='text/css'/>
41
+ </head>
42
+ <body>
43
+ <p>
44
+ <strong>Header</strong>
45
+ </p>
46
+ <div>this is our first html doc!</div>
47
+ <p>its really awesome</p>
48
+ <p>dot operator withconcat<span>nested span</span>
49
+ </p>
50
+ </body>
51
+ </html>
52
+
53
+ == REQUIREMENTS:
54
+
55
+ * RedCloth
56
+ * REXML
57
+
58
+ == INSTALL:
59
+
60
+ gem install rbml
61
+
62
+ == LICENSE:
63
+
64
+ (The MIT License)
65
+
66
+ Copyright (c) 2007 FIX
67
+
68
+ Permission is hereby granted, free of charge, to any person obtaining
69
+ a copy of this software and associated documentation files (the
70
+ 'Software'), to deal in the Software without restriction, including
71
+ without limitation the rights to use, copy, modify, merge, publish,
72
+ distribute, sublicense, and/or sell copies of the Software, and to
73
+ permit persons to whom the Software is furnished to do so, subject to
74
+ the following conditions:
75
+
76
+ The above copyright notice and this permission notice shall be
77
+ included in all copies or substantial portions of the Software.
78
+
79
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
80
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
81
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
82
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
83
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
84
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
85
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/rbml.rb'
6
+
7
+ Hoe.new('rbml', Rbml::VERSION) do |p|
8
+ p.rubyforge_name = 'rbml'
9
+ p.summary = 'Rbml is a dsl framework for writing other languages in ruby'
10
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
11
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
12
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
13
+ end
14
+
15
+ # vim: syntax=Ruby
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
3
+ $template_dir = File.dirname(ARGV[0])
4
+ require 'rbml'
5
+ ::Rbml::Processor.run(ARGV)
@@ -0,0 +1,10 @@
1
+ module Rbml
2
+ module Base
3
+ def find_partial(str)
4
+ arr = str.split("/")
5
+ arr.last[0,0] = "_"
6
+ filename = ($template_dir + '/' + arr.join("/") + '.rbml')
7
+ __instance_eval__ File.read(filename)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,48 @@
1
+ require 'languages/xml'
2
+
3
+ module Rbml
4
+ module Xhtml
5
+ include Xml
6
+
7
+ def tags; ['body', 'title', 'head', 'p', 'div', 'ul', 'li', 'html', 'a', 'br', 'span']end
8
+
9
+ def stylesheets *sheets
10
+ all_sheets = ''
11
+ sheets.each {|sheet| all_sheets << stylesheet(sheet)}
12
+ all_sheets
13
+ end
14
+
15
+ def stylesheet what
16
+ "<link rel='stylesheet' href='/stylesheets/#{what}.css' type='text/css' />"
17
+ end
18
+
19
+ def doctype(options)
20
+ strictness = options[:strict] ? "Strict" : "Transitional"
21
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 #{strictness}//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-#{strictness.downcase}.dtd\">"
22
+ end
23
+
24
+ def start_tag(*options)
25
+ "#{doctype options.first}<html>"
26
+ end
27
+
28
+ def end_tag *options
29
+ "</html>"
30
+ end
31
+
32
+ def include(str)
33
+ find_partial(str)
34
+ end
35
+
36
+ def textilize(str)
37
+ require 'rubygems'
38
+ require 'redcloth'
39
+ RedCloth.new(str).to_html
40
+ end
41
+
42
+ def method_missing(method, *args, &blk)
43
+ if tags.include? method.to_s
44
+ print_tag(method.to_s, args, &blk)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,35 @@
1
+ require 'languages/base'
2
+
3
+ module Rbml
4
+ module Xml
5
+ include Base
6
+ def tags;[]end
7
+ def inline what; what end
8
+
9
+ alias :i :inline
10
+
11
+ def method_missing(method, *args, &blk)
12
+ print_tag(method.to_s, args, &blk)
13
+ end
14
+
15
+ def print_tag(tag, *args, &blk)
16
+ options = {}
17
+ content = ''
18
+ args.flatten.each do |a|
19
+ content = a if a.kind_of? String
20
+ options.merge! a if a.kind_of? Hash
21
+ end
22
+
23
+ attributes = ' '
24
+ options.each{|k, v| attributes << "#{k}='#{v}' "} if options.kind_of? Hash
25
+
26
+ if block_given?
27
+ ["<#{tag}#{attributes unless attributes.blank?}>", blk, "</#{tag}>"]
28
+ elsif !content.blank?
29
+ "<#{tag}#{attributes unless attributes.blank?}>#{content}</#{tag}>"
30
+ else
31
+ "<#{tag}#{attributes unless attributes.blank?} />"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,51 @@
1
+ module Rbml
2
+ class Doc
3
+ attr_accessor :dsl
4
+ attr_accessor :assemble_doc
5
+ attr_accessor :formatted_doc
6
+
7
+ def initialize(language=nil)
8
+ @dsl = BlankSlate.new(language)
9
+ end
10
+
11
+ def instance_eval_each(code, &blk)
12
+ $whiner = ::Kernel::BlockBreaker.new do |name, args, block|
13
+ yield @dsl.__send__(name, *args, &block)
14
+ end
15
+ $whiner.__instance_eval__ &code
16
+ end
17
+
18
+ def self.render(language, options, &block)
19
+ d = Doc.new(language)
20
+ d.assemble_doc = ""
21
+ display = lambda do |result|
22
+ if result.kind_of? Array
23
+ result.each {|r| r.kind_of?(Proc) ? d.instance_eval_each(r, &display) : d.assemble_doc<<(r) }
24
+ else
25
+ d.assemble_doc << result
26
+ end
27
+ end
28
+ d.assemble_doc << d.dsl.start_tag(options)
29
+ d.instance_eval_each(block, &display)
30
+ d.assemble_doc << d.dsl.end_tag
31
+
32
+
33
+ d.formatted_doc = ''
34
+ begin
35
+ d.format
36
+ ensure
37
+ d.print
38
+ end
39
+ end
40
+
41
+ def format
42
+ require 'rexml/document'
43
+ doc = REXML::Document.new assemble_doc
44
+ doc.write formatted_doc, 1
45
+ end
46
+
47
+ def print
48
+ puts formatted_doc.blank? ? assemble_doc : formatted_doc
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,40 @@
1
+ module Kernel
2
+ def render_doc(options, &block)
3
+ require "languages/#{method_name}"
4
+ language = method_name.to_m
5
+ Rbml::Doc.render(language, options, &block)
6
+ end
7
+ undef p
8
+ alias :xhtml :render_doc
9
+ def method_name; caller[0][/`([^']*)'/, 1]; end
10
+
11
+ class BlankSlate
12
+ alias :__instance_eval__ :instance_eval
13
+ alias :__extend__ :extend
14
+ alias :__respond_to? :respond_to?
15
+
16
+ instance_methods.each {|m| undef_method m unless m =~ /^__/ }
17
+
18
+ def initialize(mod = nil)
19
+ __extend__ mod if mod
20
+ end
21
+ end
22
+
23
+ class BlockBreaker < BlankSlate
24
+
25
+ def initialize(&block)
26
+ if block_given?
27
+ @handler = block
28
+ else
29
+ raise NoBlockGiven, "Must be a block to whine to"
30
+ end
31
+ end
32
+
33
+ def method_missing(name, *args, &block)
34
+ @handler.call(name, args, block)
35
+ end
36
+ end
37
+
38
+ class NoBlockGiven < StandardError; end
39
+ end
40
+
@@ -0,0 +1,10 @@
1
+ class String
2
+ def blank?
3
+ strip.empty?
4
+ end
5
+
6
+ def to_m
7
+ module_name = self[0,1].upcase + self[1, self.length]
8
+ Rbml.const_get(module_name)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Rbml
2
+ class Processor
3
+ def self.run(argv)
4
+ # If ARGV is a glob, it will actually each over each one of the matching files.
5
+ argv.each do |file_or_dir|
6
+ load file_or_dir
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
2
+ module Rbml
3
+ VERSION = '0.0.1'
4
+ end
5
+ require 'extensions/kernel'
6
+ require 'extensions/string'
7
+ require 'doc'
8
+ require 'processor'
@@ -0,0 +1,62 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ class XhtmlSpecr
4
+ include ::Rbml::Xhtml
5
+ end
6
+
7
+ context "a new Doc instance" do
8
+ setup do
9
+ @doc = XhtmlSpecr.new
10
+ end
11
+
12
+ specify "should render doctype" do
13
+ @doc.doctype({:type=>:xhtml, :version=>"1.0", :strict=>false}).should == "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
14
+ end
15
+
16
+ specify 'should render head' do
17
+ @doc.instance_eval_each(head{ }).should_have_tag '//head'
18
+ end
19
+
20
+ specify 'should render body' do
21
+ @doc.body{}.should_have_tag '//body'
22
+ end
23
+
24
+ specify 'should be able to set attributes on body' do
25
+ @doc.body(:attributes =>{:id => 'test'}){}.should_have_tag "//body[@id='test']"
26
+ end
27
+ end
28
+
29
+ context 'when rendering the head' do
30
+ setup do
31
+ @doc = ::Rbml::Doc.new
32
+ end
33
+
34
+ specify 'should be able to set a title' do
35
+ @doc.head{title "test"}.should_have_tag '//title'
36
+ @doc.head{title "test"}.tag('//title').should_contain "test"
37
+ end
38
+
39
+ specify 'should be able to set stylesheets' do
40
+ @doc.head{stylesheets :base}.should_have_tag "//link[@href='/stylesheets/base.css']"
41
+ end
42
+
43
+ specify 'should be able to set multiple stylesheets' do
44
+ @doc.head{stylesheets :base, :test}.should_have_tag ["//link[@href='/stylesheets/base.css']", "//link[@href='/stylesheets/base.css']"]
45
+ end
46
+
47
+ specify 'should be able to handle inline strings' do
48
+ @doc.head{"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>"}.should == "test"
49
+ end
50
+ end
51
+
52
+ context "loading template into render" do
53
+ setup do
54
+ @doc = mock('doc')
55
+ ::Rbml::Doc.should_receive(:new).and_return(@doc)
56
+ end
57
+
58
+ specify "should pass to instance_eval_each" do
59
+ @doc.should_receive(:instance_eval_each)
60
+ load File.dirname(__FILE__) + '/fixtures/test.rbml'
61
+ end
62
+ end
@@ -0,0 +1,18 @@
1
+ div do
2
+ inline "partial text"
3
+ ul :id=>"partiallist", :class => 'cool' do
4
+ li do
5
+ inline "hello world"
6
+ br
7
+ i "how are you"
8
+ end
9
+ li "item one"
10
+ li do
11
+ inline "item two"
12
+ a :href=>"http://google.com" do
13
+ inline "with link"
14
+ end
15
+ end
16
+ end
17
+ include "sublist/sublist"
18
+ end
@@ -0,0 +1,3 @@
1
+ ul :id=>"sublist" do
2
+ li "sublist item"
3
+ end
@@ -0,0 +1,18 @@
1
+ xhtml :doctype => {:type=>:xhtml, :version=>"1.0", :strict=>false} do
2
+ head do
3
+ title "Sample Site"
4
+ stylesheets :base, :links
5
+ #COMMENTS DONT GET EVAL'd
6
+ end
7
+
8
+ body do
9
+ textilize "*Header*"
10
+ div "this is our first html doc!"
11
+ p "its really awesome"
12
+ myvar = "withconcat"
13
+ p do
14
+ inline "dot operator #{myvar}"
15
+ span "nested span"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ xhtml :doctype => {:type=>:xhtml, :version=>"1.0", :strict=>false} do
2
+ head do
3
+ title "Bridgewater Golf Club"
4
+ stylesheets :base, :links, :membership, :contact
5
+ # meta_tag "content-type", :content=>"text/html; charset=utf-8"
6
+ end
7
+
8
+ body do
9
+ textilize "*Header*"
10
+ div "this is our first html doc!"
11
+ p "its really awesome"
12
+ myvar = "withconcat"
13
+ p do
14
+ inline "dot operator #{myvar}"
15
+ span "nested span"
16
+ end
17
+ include "partial"
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ def sample_body
4
+ body do
5
+ p 'whatup'
6
+ end
7
+ end
8
+
9
+ context "my extended object" do
10
+ setup do
11
+ @doc = ::Rbml::Doc.new
12
+ #@breaker = mock('blockbreaker')
13
+ @myproc = Proc.new do
14
+ title "line 1"
15
+ div "line 2"
16
+ end
17
+ end
18
+
19
+ specify 'instance_eval_each should be callable' do
20
+ lambda{ @doc.instance_eval_each(@myproc) {lambda{sample_body}} }.should_not_raise
21
+ end
22
+
23
+ specify "instance_eval_each should work" do
24
+ arr = []
25
+ @doc.instance_eval_each(@myproc) {|result| arr << result }
26
+ arr.length.should_be 2
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ context 'when rendering the document' do
4
+ setup do
5
+ ::Rbml::Processor.run(File.dirname(__FILE__) + '/fixtures/test.rbml')
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require_gem 'rspec'
3
+ require 'spec'
4
+ require 'hpricot'
5
+ $: << File.dirname(__FILE__) + "/../lib"
6
+ require 'rbml'
7
+
8
+ class Hpricot::Elem
9
+ def should_contain(value)
10
+ self.inner_text.include?(value)
11
+ end
12
+
13
+ # courtesy of 'thomas' from the comments
14
+ # of _whys blog - get in touch if you want a better credit!
15
+ def inner_text
16
+ self.children.collect do |child|
17
+ child.is_a?(Hpricot::Text) ? child.content : child.inner_text
18
+ end.join.strip
19
+ end
20
+ end
21
+
22
+ class String
23
+ def should_have_tag(*search_string)
24
+ search_string.each { |string| Hpricot(self).search(string).should_not_be_empty }
25
+ end
26
+
27
+ def tag(search_string)
28
+ Hpricot(self).at(search_string)
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: rbml
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-01-28 00:00:00 -05:00
8
+ summary: Rbml is a dsl framework for writing other languages in ruby
9
+ require_paths:
10
+ - lib
11
+ email: ryand-ruby@zenspider.com
12
+ homepage: " by Jake Howerton, Evan Short"
13
+ rubyforge_project: rbml
14
+ description: "== FEATURES/PROBLEMS: * XML support is totally untested since we don't need it == SYNOPSIS: xhtml :doctype => {:type=>:xhtml, :version=>\"1.0\", :strict=>false} do head do title \"Sample Site\" stylesheets :base, :links #COMMENTS DONT GET EVAL'd end body do textilize \"*Header*\" div \"this is our first html doc!\" p \"its really awesome\" myvar = \"withconcat\" p do inline \"dot operator #{myvar}\" span \"nested span\" end end end Outputs"
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Ryan Davis
30
+ files:
31
+ - History.txt
32
+ - Manifest.txt
33
+ - README.txt
34
+ - Rakefile
35
+ - bin/rbmlout
36
+ - languages/base.rb
37
+ - languages/xhtml.rb
38
+ - languages/xml.rb
39
+ - lib/doc.rb
40
+ - lib/extensions/kernel.rb
41
+ - lib/extensions/string.rb
42
+ - lib/processor.rb
43
+ - lib/rbml.rb
44
+ - spec/doc_spec.rb
45
+ - spec/fixtures/_partial.rbml
46
+ - spec/fixtures/sublist/_sublist.rbml
47
+ - spec/fixtures/synopsis.rbml
48
+ - spec/fixtures/test.rbml
49
+ - spec/object_spec.rb
50
+ - spec/rbml_spec.rb
51
+ - spec/spec_helper.rb
52
+ test_files: []
53
+
54
+ rdoc_options: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ executables:
59
+ - rbmlout
60
+ extensions: []
61
+
62
+ requirements: []
63
+
64
+ dependencies:
65
+ - !ruby/object:Gem::Dependency
66
+ name: hoe
67
+ version_requirement:
68
+ version_requirements: !ruby/object:Gem::Version::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.1.7
73
+ version: