laydown 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 jbe
1
+ Copyright (c) 2011 Jostein Berre Eliassen
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -31,9 +31,9 @@ How about something like this?
31
31
  favicon: 'pill.png',
32
32
  keywords: 'man, #{@keywords}',
33
33
 
34
- css: ['site.css', '#{@css}'],
35
- js: ['app.js', '#{@js}'],
36
- inline_js: ['alert("#{msg}");'],
34
+ css: ['site.css', :@css],
35
+ js: ['app.js', :@js],
36
+ inline_js: ['alert("#{@msg}");'],
37
37
 
38
38
  head: '<meta soundtrack="Piazzolla">',
39
39
  body: '#{yield}', # default
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
data/laydown.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{laydown}
8
- s.version = "0.5.0"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jbe"]
12
- s.date = %q{2011-02-20}
12
+ s.date = %q{2011-02-25}
13
13
  s.description = %q{Provides a simple Ruby DSL for defining HTML5 layouts for web apps. For those who has written the same layout too many times.}
14
14
  s.email = %q{post@jostein.be}
15
15
  s.extra_rdoc_files = [
data/lib/laydown.rb CHANGED
@@ -5,68 +5,49 @@ require 'temple/utils'
5
5
 
6
6
  module Laydown
7
7
 
8
+ RAW_TEMPLATE = File.read(File.join(
9
+ File.dirname(__FILE__), 'template.rb'
10
+ ))
11
+
8
12
  DEFAULT_TEMPLATE = {
9
13
  :charset => 'utf-8',
10
14
  :title => nil,
11
15
  :description => nil,
12
16
  :favicon => nil,
13
- :keywords => nil,
17
+ :keywords => [],
14
18
  :css => [],
15
19
  :js => [],
16
20
  :inline_js => [],
17
21
  :head => [],
18
22
  :body_class => nil,
19
- :body => '#{yield}',
20
- :ga_code => nil
23
+ :body => :yield,
24
+ :ga_code => :@ga_code
21
25
  }
22
26
 
27
+ ARRAY_PROPS = [:keywords, :css, :js, :inline_js, :head]
28
+
23
29
  def self.compile(template={})
24
30
 
25
31
  template = DEFAULT_TEMPLATE.merge(template)
26
32
 
27
- [:charset, :title, :description, :favicon,
28
- :keywords, :body_class, :body, :ga_code
29
- ].each do |k|
30
- template[k] = case template[k]
31
- when Array then template[k].join(template[k] == :keywords ? ', ' : '')
32
- when String then template[k]
33
- else template[k].to_s
34
- end
35
- end
36
-
37
- [:css, :js, :inline_js, :head].each do |k|
33
+ ARRAY_PROPS.each do |k|
38
34
  template[k] = Array(template[k]).flatten.compact
39
35
  end
40
36
 
41
- compiled = read_raw_template.gsub(/data\[:([a-zA-Z0-9_]+)\]/) do |m|
42
- val = template[:"#{$1}"]
43
- case val
44
- when String then interpolatize(val)
45
- when nil then 'nil'
46
- when Array then interpolatize(
47
- val.map {|v| v.to_s }
48
- )
49
- else val.to_s
50
- end
37
+ RAW_TEMPLATE.gsub(/data\[:([a-zA-Z0-9_]+)\]/) do |m|
38
+ literalize template[:"#{$1}"]
51
39
  end
52
-
53
- puts compiled
54
- compiled
55
- end
56
-
57
- def self.new(hsh={})
58
- Template.new(hsh)
59
- end
60
-
61
- def self.read_raw_template
62
- File.read(File.join(
63
- File.dirname(__FILE__), 'template.rb'
64
- ))
65
40
  end
66
41
 
67
- def self.interpolatize(obj)
68
- puts obj
69
- obj.inspect.gsub(/\\#\{/, '#{')
42
+ def self.literalize(obj)
43
+ case obj
44
+ when String then obj.inspect.gsub(/\\#\{/, '#{') + "+''"
45
+ when Symbol then obj.to_s
46
+ when nil then 'nil'
47
+ when Array
48
+ '[' + obj.map {|o| literalize(o) }.join(', ') + ']'
49
+ else obj.to_s.inspect
50
+ end
70
51
  end
71
52
 
72
53
  class Template < Tilt::Template
@@ -83,6 +64,10 @@ module Laydown
83
64
  @src
84
65
  end
85
66
  end
67
+
68
+ def self.new(hsh={})
69
+ Template.new(hsh)
70
+ end
86
71
  end
87
72
 
88
73
 
data/lib/template.rb CHANGED
@@ -10,8 +10,8 @@ _buf = [] ; _temple_pre_tags = /<pre|<textarea/ ; _buf << ("<!DOCTYPE html><html
10
10
  "") ; end ; if data[:description] ;
11
11
  ; _buf << ("<meta content=\"#{Temple::Utils.escape_html((data[:description]))}\" name=\"description\">"\
12
12
  ""\
13
- "") ; end ; if data[:keywords] ;
14
- ; _buf << ("<meta content=\"#{Temple::Utils.escape_html((data[:keywords]))}\" name=\"keywords\">"\
13
+ "") ; end ; if data[:keywords].any? ;
14
+ ; _buf << ("<meta content=\"#{Temple::Utils.escape_html((data[:keywords].join(', ')))}\" name=\"keywords\">"\
15
15
  ""\
16
16
  "") ; end ; data[:css].flatten.each do |url| ;
17
17
  ; unless url == '' ;
@@ -28,9 +28,10 @@ _buf = [] ; _temple_pre_tags = /<pre|<textarea/ ; _buf << ("<!DOCTYPE html><html
28
28
  ; _buf << (code) ;
29
29
  ;
30
30
  ; end ; end ; _buf << ("</script>") ; end ; if data[:head] ;
31
- ; _buf << (data[:head]) ;
31
+ ; data[:head].each do |item| ;
32
+ ; _buf << (item) ;
32
33
  ;
33
- ; end ; _buf << ("</head><body class=\"#{Temple::Utils.escape_html((data[:body_class]))}\">"\
34
+ ; end ; end ; _buf << ("</head><body class=\"#{Temple::Utils.escape_html((data[:body_class]))}\">"\
34
35
  "#{data[:body]}"\
35
36
  ""\
36
37
  "") ; if data[:ga_code] ;
data/spec/laydown_spec.rb CHANGED
@@ -12,8 +12,8 @@ describe Laydown do
12
12
  favicon: 'applesuck.png',
13
13
  keywords: 'apple suck lol #{@keywords}',
14
14
 
15
- css: ['applesuck.css', '#{@css}'],
16
- js: ['applesuck.js', '#{@js}'],
15
+ css: ['applesuck.css', :@css],
16
+ js: ['applesuck.js', :@js],
17
17
  inline_js: 'alert("#{@msg}");',
18
18
 
19
19
  head: '<meta generator="Ubuntu">',
@@ -25,6 +25,7 @@ describe Laydown do
25
25
  it 'generates properly' do
26
26
  @reason = 'just because'
27
27
  @msg = 'boo'
28
+ @css = ['hubba.css', 'laaa.css']
28
29
  str = subject.render(self) { 'This is the body.' }
29
30
  str.should == nil
30
31
 
data/template.slim CHANGED
@@ -10,8 +10,8 @@ html
10
10
  - if data[:description]
11
11
  meta name="description" content=data[:description]
12
12
 
13
- - if data[:keywords]
14
- meta name="keywords" content=data[:keywords]
13
+ - if data[:keywords].any?
14
+ meta name="keywords" content=data[:keywords].join(', ')
15
15
 
16
16
  - data[:css].flatten.each do |url|
17
17
  - unless url == ''
@@ -28,7 +28,8 @@ html
28
28
  == code
29
29
 
30
30
  - if data[:head]
31
- == data[:head]
31
+ - data[:head].each do |item|
32
+ == item
32
33
 
33
34
  body class=data[:body_class]
34
35
  == data[:body]
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 5
7
+ - 6
8
8
  - 0
9
- version: 0.5.0
9
+ version: 0.6.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - jbe
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-20 00:00:00 +01:00
17
+ date: 2011-02-25 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency