laydown 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 jbe
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/README ADDED
@@ -0,0 +1,36 @@
1
+ #
2
+ # .
3
+ # «=» ☺
4
+ # ^
5
+ # «« ^¨^ »»
6
+ # LAYDOWN
7
+ # ''|'|''
8
+ # | |
9
+ # | |
10
+ # | |
11
+ #'''''''''''''''''''''''''''''
12
+ # $ gem install laydown
13
+ # «=»
14
+ # ^
15
+ # $ «« ^¨^ »» $
16
+ # http://jostein.be
17
+ # sample: '' ''
18
+
19
+ require 'laydown'
20
+
21
+ layout = Laydown.layout do
22
+ title 'A man in a cave'
23
+ description 'A man is sitting in a cave. What will he do?'
24
+ keywords 'man, cave', @keywords
25
+ favicon 'maninacave.png'
26
+ css '/maninacave/style.css'
27
+ css @css
28
+ js '/maninacave/site.js'
29
+ js @js
30
+
31
+ body "<h1>A man in\na cave</h1>"
32
+ end
33
+
34
+ @css = 'somesheet.css'
35
+
36
+ puts Layout.render(self) # => beautiful html5
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "laydown"
8
+ gem.summary = %Q{Pure Ruby HTML5 layout DSL for microframeworks.}
9
+ gem.description = %Q{Provides a simple Ruby DSL for defining HTML5 layouts for web apps. For those of us who has written basically the same html head 200 times and feels like stripping.}
10
+ gem.email = "post@jostein.be"
11
+ gem.homepage = "http://github.com/jbe/laydown"
12
+ gem.authors = ["jbe"]
13
+ gem.add_dependency "instant_dsl", ">= 0"
14
+ gem.add_dependency "markaby", ">= 0"
15
+ gem.add_development_dependency "tenjin", ">= 0"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ namespace :build do
24
+ desc 'Builds Tenjin templates'
25
+ task :templates do
26
+ sh 'rbtenjin -s templates/default_layout.tenjin.html > lib/templates/default_layout.rb'
27
+ end
28
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/laydown.rb ADDED
@@ -0,0 +1,66 @@
1
+
2
+ require 'markaby'
3
+ require 'instant_dsl'
4
+
5
+ module Laydown
6
+
7
+ DSL_WORDS = [:title, :description, :favicon, :keywords, :css, :js, :body]
8
+ DSL = InstantDSL[*DSL_WORDS]
9
+
10
+ class NoScope < Object; end
11
+
12
+ class TemplateScope
13
+ def initialize(v)
14
+ @title = v[:title].join
15
+ @description = v[:description].join
16
+ @favicon = v[:favicon].first
17
+ @keywords = v[:keywords].join(', ')
18
+ @stylesheets = v[:css].compact
19
+ @javascripts = v[:js].compact
20
+ @body = v[:body].join("\n")
21
+ end
22
+ end
23
+
24
+ def self.layout(&conf)
25
+ Template.new(&conf)
26
+ end
27
+
28
+ class Template
29
+ def initialize(&conf)
30
+ @conf = conf
31
+ end
32
+
33
+ def render(source_scope=::Laydown::NoScope.new)
34
+ dsl_scope = ::Laydown::DSL.new
35
+ copy_instance_variables(source_scope, dsl_scope)
36
+ dsl_scope.send :instance_eval, &@conf
37
+
38
+ scope = ::Laydown::TemplateScope.new(dsl_scope.dsl_values)
39
+
40
+ tpath = File.expand_path('../templates/default_layout.rb', __FILE__)
41
+ template = IO.read(tpath)
42
+
43
+ scope.send :instance_eval, template, tpath
44
+ end
45
+
46
+ private
47
+ def copy_instance_variables(a, b, destr=false)
48
+ a.instance_variables.each do |name|
49
+ if !b.instance_variable_defined?(name) or destr
50
+ b.instance_variable_set(name, a.instance_variable_get(name))
51
+ end
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
@@ -0,0 +1,25 @@
1
+ _buf = ''; _buf << %Q`<!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>#{@title}</title>
6
+ <meta name="description" content="#{@description}">
7
+ <meta name="keywords" content="#{@keywords}">\n`
8
+ if @favicon
9
+ _buf << %Q` <link rel="shortcun icon" href="#{@favicon}">\n`
10
+ end
11
+ _buf << %Q`\n`
12
+ @stylesheets.each do |sheet|
13
+ _buf << %Q` <link rel="stylesheet" type="text/css" href="#{sheet}">\n`
14
+ end
15
+ _buf << %Q`\n`
16
+ @javascripts.each do |script|
17
+ _buf << %Q` <script src="#{script}" ></script>\n`
18
+ end
19
+ _buf << %Q` </head>
20
+
21
+ <body>
22
+ #{ @body }
23
+ </body>
24
+ </html>\n`
25
+ _buf.to_s
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>#{@title}</title>
6
+ <meta name="description" content="#{@description}">
7
+ <meta name="keywords" content="#{@keywords}">
8
+ <?rb if @favicon ?>
9
+ <link rel="shortcun icon" href="#{@favicon}">
10
+ <?rb end ?>
11
+
12
+ <?rb @stylesheets.each do |sheet| ?>
13
+ <link rel="stylesheet" type="text/css" href="#{sheet}">
14
+ <?rb end ?>
15
+
16
+ <?rb @javascripts.each do |script| ?>
17
+ <script src="#{script}" ></script>
18
+ <?rb end ?>
19
+ </head>
20
+
21
+ <body>
22
+ #{ @body }
23
+ </body>
24
+ </html>
data/test/rough.rb ADDED
@@ -0,0 +1,19 @@
1
+ require './lib/laydown'
2
+
3
+
4
+ Layout = Laydown.layout do
5
+ title 'A man in a cave'
6
+ description 'A man is sitting in a cave. What will he do?'
7
+ keywords 'man, cave, mystery'
8
+ favicon 'maninacave.png'
9
+ css '/maninacave/style.css'
10
+ css @css
11
+ js '/maninacave/site.js'
12
+ js @js
13
+
14
+ body "<h1>A man in\na cave</h1>"
15
+ end
16
+
17
+ @css = 'somesheet.css'
18
+
19
+ puts Layout.render(self)
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: laydown
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - jbe
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-08 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: instant_dsl
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: markaby
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: tenjin
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id003
59
+ description: Provides a simple Ruby DSL for defining HTML5 layouts for web apps. For those of us who has written basically the same html head 200 times and feels like stripping.
60
+ email: post@jostein.be
61
+ executables: []
62
+
63
+ extensions: []
64
+
65
+ extra_rdoc_files:
66
+ - LICENSE
67
+ - README
68
+ files:
69
+ - .document
70
+ - .gitignore
71
+ - LICENSE
72
+ - README
73
+ - Rakefile
74
+ - VERSION
75
+ - lib/laydown.rb
76
+ - lib/templates/default_layout.rb
77
+ - templates/default_layout.tenjin.html
78
+ - test/rough.rb
79
+ has_rdoc: true
80
+ homepage: http://github.com/jbe/laydown
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --charset=UTF-8
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.3.7
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Pure Ruby HTML5 layout DSL for microframeworks.
111
+ test_files:
112
+ - test/rough.rb