petroglyph 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/padrino/petroglyph.rb +4 -0
- data/lib/petroglyph/railtie.rb +2 -2
- data/lib/petroglyph/scope.rb +3 -3
- data/lib/petroglyph/version.rb +1 -1
- data/lib/petroglyph.rb +7 -8
- data/lib/rails/2.x/petroglyph.rb +24 -0
- data/lib/rails/3.x/petroglyph.rb +26 -0
- data/lib/sinatra/petroglyph.rb +4 -5
- data/spec/fixtures/views/partials/nested_partial.pg +1 -0
- data/spec/scope_spec.rb +10 -0
- metadata +14 -11
- data/lib/petroglyph/template.rb +0 -64
data/lib/petroglyph/railtie.rb
CHANGED
data/lib/petroglyph/scope.rb
CHANGED
@@ -76,8 +76,8 @@ module Petroglyph
|
|
76
76
|
|
77
77
|
def partial(name, locals = {})
|
78
78
|
data = Petroglyph.partial(name, file)
|
79
|
-
scope = Scope.new(@context, locals)
|
80
|
-
scope.instance_eval(data)
|
79
|
+
scope = Scope.new(@context, locals, file)
|
80
|
+
scope.instance_eval(data.to_s)
|
81
81
|
merge scope.value
|
82
82
|
end
|
83
83
|
|
@@ -85,7 +85,7 @@ module Petroglyph
|
|
85
85
|
if @locals and @locals.has_key?(method)
|
86
86
|
@locals[method]
|
87
87
|
elsif @context.respond_to?(method)
|
88
|
-
@context.send(method)
|
88
|
+
@context.send(method, *args)
|
89
89
|
else
|
90
90
|
super
|
91
91
|
end
|
data/lib/petroglyph/version.rb
CHANGED
data/lib/petroglyph.rb
CHANGED
@@ -2,13 +2,9 @@ require 'json'
|
|
2
2
|
|
3
3
|
require 'petroglyph/scope'
|
4
4
|
require 'petroglyph/engine'
|
5
|
-
require 'petroglyph/railtie' if defined?(Rails) && Rails.version =~ /^3/
|
6
5
|
|
7
6
|
module Petroglyph
|
8
7
|
class << self
|
9
|
-
def register!
|
10
|
-
require 'petroglyph/template'
|
11
|
-
end
|
12
8
|
def partial(filename, template_filename)
|
13
9
|
basedir = File.dirname(template_filename)
|
14
10
|
[basedir, "#{basedir}/partials"].each do |dir|
|
@@ -20,9 +16,12 @@ module Petroglyph
|
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
23
|
-
if defined?
|
24
|
-
require 'padrino
|
25
|
-
|
19
|
+
if defined? Padrino
|
20
|
+
require 'padrino/petroglyph'
|
21
|
+
elsif defined? Sinatra
|
22
|
+
require 'sinatra/petroglyph'
|
26
23
|
elsif defined?(Rails) && Rails.version =~ /^2/
|
27
|
-
|
24
|
+
require 'rails/2.x/petroglyph'
|
25
|
+
elsif defined?(Rails) && Rails.version =~ /^3/
|
26
|
+
require 'petroglyph/railtie'
|
28
27
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
if defined?(Tilt)
|
2
|
+
require 'tilt/petroglyph'
|
3
|
+
end
|
4
|
+
|
5
|
+
# Rails 2.X Template
|
6
|
+
if defined?(Rails) && Rails.version =~ /^2/
|
7
|
+
require 'action_view/base'
|
8
|
+
require 'action_view/template'
|
9
|
+
|
10
|
+
module ActionView
|
11
|
+
module TemplateHandlers
|
12
|
+
class PetroglyphHandler < TemplateHandler
|
13
|
+
include Compilable
|
14
|
+
|
15
|
+
def compile(template) %{
|
16
|
+
::Petroglyph::Engine.new(#{template.source.inspect}).
|
17
|
+
render(self, assigns.merge(local_assigns), '#{template.filename}')
|
18
|
+
} end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActionView::Template.register_template_handler :pg, ActionView::TemplateHandlers::PetroglyphHandler
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
if defined?(Tilt)
|
2
|
+
require 'tilt/petroglyph'
|
3
|
+
end
|
4
|
+
|
5
|
+
# Rails 3.X Template
|
6
|
+
if defined?(Rails) && Rails.version =~ /^3/
|
7
|
+
module ActionView
|
8
|
+
module Template::Handlers
|
9
|
+
class Petroglyph
|
10
|
+
|
11
|
+
def call(template)
|
12
|
+
source = if template.source.empty?
|
13
|
+
File.read(template.identifier)
|
14
|
+
else
|
15
|
+
template.source
|
16
|
+
end
|
17
|
+
|
18
|
+
%{ ::Petroglyph::Engine.new(#{source.inspect}).
|
19
|
+
render(self, assigns.merge(local_assigns), '#{template.identifier}') }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
ActionView::Template.register_template_handler :pg, ActionView::Template::Handlers::Petroglyph.new
|
26
|
+
end
|
data/lib/sinatra/petroglyph.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'tilt/petroglyph'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
module Sinatra::Templates
|
4
|
+
def pg(template, options={}, locals={})
|
5
|
+
options.merge!(:default_content_type => :json)
|
6
|
+
render :pg, template, options, locals
|
8
7
|
end
|
9
8
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
partial :the_partial, :thing => 'stuff'
|
data/spec/scope_spec.rb
CHANGED
@@ -246,5 +246,15 @@ describe Petroglyph::Scope do
|
|
246
246
|
scope.value.should eq({:partial => {:thing => 'stuff'}})
|
247
247
|
end
|
248
248
|
|
249
|
+
it "finds nested partials" do
|
250
|
+
scope = Petroglyph::Scope.new
|
251
|
+
scope.file = "spec/fixtures/views/some_template.pg"
|
252
|
+
|
253
|
+
scope.node :partial do
|
254
|
+
partial :nested_partial
|
255
|
+
end
|
256
|
+
|
257
|
+
scope.value.should eq({:partial => {:thing => 'stuff'}})
|
258
|
+
end
|
249
259
|
end
|
250
260
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: petroglyph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tilt
|
16
|
-
requirement: &
|
16
|
+
requirement: &70117439374320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70117439374320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70117439367780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70117439367780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sinatra
|
38
|
-
requirement: &
|
38
|
+
requirement: &70117439367160 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70117439367160
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rack-test
|
49
|
-
requirement: &
|
49
|
+
requirement: &70117439366500 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70117439366500
|
58
58
|
description: A simple, terse, and unsurprising ruby dsl to create json views.
|
59
59
|
email:
|
60
60
|
- katrina.owen@gmail.com
|
@@ -68,18 +68,21 @@ files:
|
|
68
68
|
- Gemfile
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
|
+
- lib/padrino/petroglyph.rb
|
71
72
|
- lib/petroglyph.rb
|
72
73
|
- lib/petroglyph/engine.rb
|
73
74
|
- lib/petroglyph/railtie.rb
|
74
75
|
- lib/petroglyph/scope.rb
|
75
|
-
- lib/petroglyph/template.rb
|
76
76
|
- lib/petroglyph/version.rb
|
77
|
+
- lib/rails/2.x/petroglyph.rb
|
78
|
+
- lib/rails/3.x/petroglyph.rb
|
77
79
|
- lib/sinatra/petroglyph.rb
|
78
80
|
- lib/tilt/petroglyph.rb
|
79
81
|
- petroglyph.gemspec
|
80
82
|
- spec/engine_spec.rb
|
81
83
|
- spec/fixtures/views/helper.pg
|
82
84
|
- spec/fixtures/views/index.pg
|
85
|
+
- spec/fixtures/views/partials/nested_partial.pg
|
83
86
|
- spec/fixtures/views/partials/sub_partial.pg
|
84
87
|
- spec/fixtures/views/post.pg
|
85
88
|
- spec/fixtures/views/syntax.pg
|
data/lib/petroglyph/template.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# TILT Template
|
2
|
-
if defined?(Tilt)
|
3
|
-
class PetroglyphTemplate < Tilt::Template
|
4
|
-
def initialize_engine
|
5
|
-
return if defined?(::Petroglyph)
|
6
|
-
require_template_library 'petroglyph'
|
7
|
-
end
|
8
|
-
|
9
|
-
def prepare
|
10
|
-
options = @options.merge(:source_location => file)
|
11
|
-
@engine = ::Petroglyph::Engine.new(data, options)
|
12
|
-
end
|
13
|
-
|
14
|
-
def evaluate(scope, locals, &block)
|
15
|
-
@engine.render(scope, locals, &block)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
Tilt.register 'pg', PetroglyphTemplate
|
20
|
-
end
|
21
|
-
|
22
|
-
# Rails 2.X Template
|
23
|
-
if defined?(Rails) && Rails.version =~ /^2/
|
24
|
-
require 'action_view/base'
|
25
|
-
require 'action_view/template'
|
26
|
-
|
27
|
-
module ActionView
|
28
|
-
module TemplateHandlers
|
29
|
-
class PetroglyphHandler < TemplateHandler
|
30
|
-
include Compilable
|
31
|
-
|
32
|
-
def compile(template) %{
|
33
|
-
::Petroglyph::Engine.new(#{template.source.inspect}).
|
34
|
-
render(self, assigns.merge(local_assigns), '#{template.filename}')
|
35
|
-
} end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
ActionView::Template.register_template_handler :pg, ActionView::TemplateHandlers::PetroglyphHandler
|
41
|
-
end
|
42
|
-
|
43
|
-
# Rails 3.X Template
|
44
|
-
if defined?(Rails) && Rails.version =~ /^3/
|
45
|
-
module ActionView
|
46
|
-
module Template::Handlers
|
47
|
-
class Petroglyph
|
48
|
-
|
49
|
-
def call(template)
|
50
|
-
source = if template.source.empty?
|
51
|
-
File.read(template.identifier)
|
52
|
-
else
|
53
|
-
template.source
|
54
|
-
end
|
55
|
-
|
56
|
-
%{ ::Petroglyph::Engine.new(#{source.inspect}).
|
57
|
-
render(self, assigns.merge(local_assigns), '#{template.identifier}') }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
ActionView::Template.register_template_handler :pg, ActionView::Template::Handlers::Petroglyph.new
|
64
|
-
end
|