mullet 0.0.2 → 0.0.3
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/lib/mullet.rb +4 -3
- data/lib/mullet/{default_nested_model.rb → default_nested_scope.rb} +15 -13
- data/lib/mullet/{default_model.rb → default_scope.rb} +14 -14
- data/lib/mullet/html/attribute_command.rb +2 -2
- data/lib/mullet/html/element_renderer.rb +2 -2
- data/lib/mullet/html/for_element_renderer.rb +5 -5
- data/lib/mullet/html/if_element_renderer.rb +2 -2
- data/lib/mullet/html/{model_attribute_command.rb → scope_attribute_command.rb} +2 -2
- data/lib/mullet/html/template_loader.rb +1 -1
- data/lib/mullet/render_context.rb +9 -9
- data/lib/mullet/{model.rb → scope.rb} +2 -2
- data/lib/mullet/sinatra.rb +100 -0
- data/lib/mullet/sinatra/engine.rb +102 -0
- data/lib/mullet/version.rb +1 -1
- data/lib/mullet/view.rb +29 -0
- metadata +20 -17
- data/lib/mullet/tilt.rb +0 -37
data/lib/mullet.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
require 'mullet/
|
2
|
-
require 'mullet/
|
3
|
-
require 'mullet/
|
1
|
+
require 'mullet/default_scope'
|
2
|
+
require 'mullet/default_nested_scope'
|
3
|
+
require 'mullet/scope'
|
4
4
|
require 'mullet/template_error'
|
5
5
|
require 'mullet/version'
|
6
|
+
require 'mullet/view'
|
6
7
|
|
7
8
|
require 'mullet/html/layout'
|
8
9
|
require 'mullet/html/template'
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'mullet/
|
1
|
+
require 'mullet/default_scope'
|
2
2
|
|
3
3
|
module Mullet
|
4
4
|
|
5
|
-
# Composite
|
5
|
+
# Composite scope that combines scopes in nested scopes. Tries each scope in
|
6
6
|
# sequence until a value is successfully resolved.
|
7
|
-
class
|
8
|
-
include
|
7
|
+
class DefaultNestedScope
|
8
|
+
include Scope
|
9
9
|
|
10
10
|
# Constructor
|
11
11
|
#
|
12
|
-
# @param
|
12
|
+
# @param data_objects
|
13
13
|
# scopes in outer to inner order
|
14
|
-
def initialize(*
|
14
|
+
def initialize(*data_objects)
|
15
15
|
@scopes = []
|
16
|
-
|
16
|
+
push_scope(*data_objects)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Resolves variable name to value.
|
@@ -32,13 +32,15 @@ module Mullet
|
|
32
32
|
return NOT_FOUND
|
33
33
|
end
|
34
34
|
|
35
|
-
# Adds
|
35
|
+
# Adds new innermost nested scopes.
|
36
36
|
#
|
37
|
-
# @param
|
38
|
-
#
|
39
|
-
def push_scope(
|
40
|
-
|
41
|
-
|
37
|
+
# @param data_objects
|
38
|
+
# scopes in outer to inner order
|
39
|
+
def push_scope(*data_objects)
|
40
|
+
data_objects.each do |data|
|
41
|
+
@scopes.push(
|
42
|
+
data.respond_to?(:get_variable_value) ? data : DefaultScope.new(data))
|
43
|
+
end
|
42
44
|
end
|
43
45
|
|
44
46
|
# Removes innermost nested scope.
|
@@ -1,38 +1,32 @@
|
|
1
|
-
require 'mullet/
|
1
|
+
require 'mullet/scope'
|
2
2
|
|
3
3
|
module Mullet
|
4
4
|
|
5
|
-
# Default
|
5
|
+
# Default scope implementation which resolves variable names to values by
|
6
6
|
# reading from a data object. Given a variable name _key_, the following
|
7
7
|
# mechanisms are tried in this order:
|
8
8
|
#
|
9
|
-
# * If the variable name is
|
10
|
-
# * If the object is a `Hash`, then use _key_ as the key to retrieve the
|
11
|
-
# value from the hash.
|
9
|
+
# * If the variable name is `.`, then return the object.
|
12
10
|
# * If the object has a method named _key_ taking no parameters, then use
|
13
11
|
# the value returned from calling the method.
|
14
12
|
# * If the object has an instance variable named @_key_, then use the
|
15
13
|
# variable value.
|
14
|
+
# * If the object is a `Hash`, then use _key_ as the key to retrieve the
|
15
|
+
# value from the hash.
|
16
16
|
#
|
17
17
|
# If the value is a Proc, then use the value returned from calling it.
|
18
|
-
class
|
19
|
-
include
|
18
|
+
class DefaultScope
|
19
|
+
include Scope
|
20
20
|
|
21
21
|
def initialize(data)
|
22
22
|
@data = data
|
23
23
|
end
|
24
24
|
|
25
25
|
def fetch_impl(name)
|
26
|
-
if name == :
|
26
|
+
if name == :'.'
|
27
27
|
return @data
|
28
28
|
end
|
29
29
|
|
30
|
-
# Is the variable name a key in a Hash?
|
31
|
-
if @data.respond_to?(:fetch)
|
32
|
-
# Call the block if the key is not found.
|
33
|
-
return @data.fetch(name) {|k| @data.fetch(k.to_s(), NOT_FOUND) }
|
34
|
-
end
|
35
|
-
|
36
30
|
# Does the variable name match a method name in the object?
|
37
31
|
if @data.respond_to?(name)
|
38
32
|
method = @data.method(name)
|
@@ -47,6 +41,12 @@ module Mullet
|
|
47
41
|
return @data.instance_variable_get(variable)
|
48
42
|
end
|
49
43
|
|
44
|
+
# Is the variable name a key in a Hash?
|
45
|
+
if @data.respond_to?(:fetch)
|
46
|
+
# If the key was not found, then try to find it as a String.
|
47
|
+
return @data.fetch(name) {|k| @data.fetch(k.to_s(), NOT_FOUND) }
|
48
|
+
end
|
49
|
+
|
50
50
|
return NOT_FOUND
|
51
51
|
end
|
52
52
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'mullet/
|
1
|
+
require 'mullet/scope'
|
2
2
|
|
3
3
|
module Mullet; module HTML
|
4
4
|
|
@@ -23,7 +23,7 @@ module Mullet; module HTML
|
|
23
23
|
# attributes to update
|
24
24
|
def execute(render_context, attributes)
|
25
25
|
value = get_value(render_context)
|
26
|
-
if value ==
|
26
|
+
if value == Scope::NOT_FOUND || value == nil
|
27
27
|
# Value not found. Do not render the attribute.
|
28
28
|
attributes.delete(@attribute_name)
|
29
29
|
else
|
@@ -3,7 +3,7 @@ require 'mullet/template_error'
|
|
3
3
|
require 'mullet/html/command'
|
4
4
|
require 'mullet/html/message'
|
5
5
|
require 'mullet/html/message_attribute_command'
|
6
|
-
require 'mullet/html/
|
6
|
+
require 'mullet/html/scope_attribute_command'
|
7
7
|
|
8
8
|
module Mullet; module HTML
|
9
9
|
|
@@ -43,7 +43,7 @@ module Mullet; module HTML
|
|
43
43
|
|
44
44
|
def add_attribute_command(attribute_name, variable_name)
|
45
45
|
@attribute_commands <<
|
46
|
-
|
46
|
+
ScopeAttributeCommand.new(attribute_name, variable_name)
|
47
47
|
end
|
48
48
|
|
49
49
|
def add_attribute_commands(attribute_variable_pairs)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'mullet/html/command_element_renderer'
|
2
|
-
require 'mullet/
|
2
|
+
require 'mullet/scope'
|
3
3
|
|
4
4
|
module Mullet; module HTML
|
5
5
|
|
@@ -19,7 +19,7 @@ module Mullet; module HTML
|
|
19
19
|
|
20
20
|
alias :super_render :render
|
21
21
|
|
22
|
-
def
|
22
|
+
def render_nested_scope(data, render_context)
|
23
23
|
render_context.push_scope(data)
|
24
24
|
super_render(render_context)
|
25
25
|
render_context.pop_scope()
|
@@ -27,7 +27,7 @@ module Mullet; module HTML
|
|
27
27
|
|
28
28
|
def render(render_context)
|
29
29
|
value = render_context.get_variable_value(@variable_name)
|
30
|
-
if value ==
|
30
|
+
if value == Scope::NOT_FOUND || value == nil || value == false
|
31
31
|
return
|
32
32
|
end
|
33
33
|
|
@@ -36,11 +36,11 @@ module Mullet; module HTML
|
|
36
36
|
end
|
37
37
|
|
38
38
|
if value.respond_to?(:each)
|
39
|
-
value.each {|item|
|
39
|
+
value.each {|item| render_nested_scope(item, render_context) }
|
40
40
|
return
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
render_nested_scope(value, render_context)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'mullet/html/command_element_renderer'
|
2
|
-
require 'mullet/
|
2
|
+
require 'mullet/scope'
|
3
3
|
|
4
4
|
module Mullet; module HTML
|
5
5
|
|
@@ -19,7 +19,7 @@ module Mullet; module HTML
|
|
19
19
|
|
20
20
|
def should_render_element(render_context)
|
21
21
|
value = render_context.get_variable_value(@variable_name)
|
22
|
-
if value ==
|
22
|
+
if value == Scope::NOT_FOUND || value == nil
|
23
23
|
return false
|
24
24
|
end
|
25
25
|
|
@@ -2,8 +2,8 @@ require 'mullet/html/attribute_command'
|
|
2
2
|
|
3
3
|
module Mullet; module HTML
|
4
4
|
|
5
|
-
# Operation to set attribute value from
|
6
|
-
class
|
5
|
+
# Operation to set attribute to value resolved from a scope.
|
6
|
+
class ScopeAttributeCommand
|
7
7
|
include AttributeCommand
|
8
8
|
|
9
9
|
# Constructor
|
@@ -7,7 +7,7 @@ module Mullet; module HTML
|
|
7
7
|
# loaded templates.
|
8
8
|
#
|
9
9
|
# By default, templates render an empty string when a variable is not found
|
10
|
-
# or its value is
|
10
|
+
# or its value is nil. Call the `on_missing` and `on_nil` methods to
|
11
11
|
# configure how templates loaded by this loader should handle missing and nil
|
12
12
|
# values respectively.
|
13
13
|
class TemplateLoader
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'cgi'
|
2
|
-
require 'mullet/
|
2
|
+
require 'mullet/default_nested_scope'
|
3
3
|
|
4
4
|
module Mullet
|
5
5
|
|
@@ -20,8 +20,8 @@ module Mullet
|
|
20
20
|
# @param [#<<] output
|
21
21
|
# where to write rendered output
|
22
22
|
def initialize(data, missing_value_strategy, nil_value_strategy, output)
|
23
|
-
@
|
24
|
-
data :
|
23
|
+
@scope = data.is_a?(DefaultNestedScope) ?
|
24
|
+
data : DefaultNestedScope.new(data)
|
25
25
|
@on_missing = missing_value_strategy
|
26
26
|
@on_nil = nil_value_strategy
|
27
27
|
@output = output
|
@@ -43,7 +43,7 @@ module Mullet
|
|
43
43
|
# variable name
|
44
44
|
# @return value
|
45
45
|
def get_variable_value(name)
|
46
|
-
return @
|
46
|
+
return @scope.get_variable_value(name)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Adds a nested scope to search in subsequent lookups.
|
@@ -51,23 +51,23 @@ module Mullet
|
|
51
51
|
# @param data
|
52
52
|
# data object
|
53
53
|
def push_scope(data)
|
54
|
-
@
|
54
|
+
@scope.push_scope(data)
|
55
55
|
end
|
56
56
|
|
57
57
|
# Removes innermost nested scope.
|
58
58
|
def pop_scope()
|
59
|
-
@
|
59
|
+
@scope.pop_scope()
|
60
60
|
end
|
61
61
|
|
62
|
-
# Gets
|
62
|
+
# Gets scope value that is intended for display in the rendered output.
|
63
63
|
# Applies configured strategies for handling missing and nil values.
|
64
64
|
#
|
65
65
|
# @param [Symbol] key
|
66
66
|
# variable name
|
67
67
|
# @return value
|
68
68
|
def get_display_value(key)
|
69
|
-
value = @
|
70
|
-
if value ==
|
69
|
+
value = @scope.get_variable_value(key)
|
70
|
+
if value == Scope::NOT_FOUND
|
71
71
|
value = @on_missing.call(key)
|
72
72
|
end
|
73
73
|
if value == nil
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Mullet
|
2
2
|
|
3
|
-
# A
|
3
|
+
# A scope responds to the method `get_variable_value` taking a variable name
|
4
4
|
# argument and returning the variable value.
|
5
|
-
module
|
5
|
+
module Scope
|
6
6
|
|
7
7
|
# special value indicating variable name was not found
|
8
8
|
NOT_FOUND = Object.new()
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'mullet/sinatra/engine'
|
2
|
+
require 'sinatra/base'
|
3
|
+
|
4
|
+
module Mullet
|
5
|
+
|
6
|
+
# Sinatra extension for rendering views with Mullet.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# require 'mullet/sinatra'
|
11
|
+
#
|
12
|
+
# class App < Sinatra::Base
|
13
|
+
# register Mullet::Sinatra
|
14
|
+
#
|
15
|
+
# set :mullet, {
|
16
|
+
# # path to folder containing template .html files. If not set, then
|
17
|
+
# # default is `settings.views`
|
18
|
+
# template_path: "views"
|
19
|
+
# }
|
20
|
+
#
|
21
|
+
# get '/' do
|
22
|
+
# mullet :index
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# When `mullet :index` is called, the engine will attempt to load a Ruby view
|
27
|
+
# class named `Views::Index` from the `views/index.rb` file. If the view
|
28
|
+
# class is not found, then the engine will render the template file
|
29
|
+
# `view/index.html` directly.
|
30
|
+
#
|
31
|
+
# By default, the rendered page will passed to a layout view named `:layout`.
|
32
|
+
# The rendered page content is passed to the layout template in the variable
|
33
|
+
# `content`.
|
34
|
+
module Sinatra
|
35
|
+
module Helpers
|
36
|
+
@@engine = Mullet::Sinatra::Engine.new()
|
37
|
+
|
38
|
+
def mullet(view_name, options={}, locals={})
|
39
|
+
# The options hash may contain a key :locals with the value being a
|
40
|
+
# hash mapping variable names to values.
|
41
|
+
locals.merge!(options.delete(:locals) || {})
|
42
|
+
|
43
|
+
# Get application settings.
|
44
|
+
view_options = { root: settings.root, views: settings.views }
|
45
|
+
|
46
|
+
if settings.respond_to?(:mullet)
|
47
|
+
view_options = settings.mullet.merge(view_options)
|
48
|
+
end
|
49
|
+
|
50
|
+
view_options.merge!(options)
|
51
|
+
|
52
|
+
# Copy instance variables set by Sinatra application.
|
53
|
+
application_data = Object.new()
|
54
|
+
instance_variables.each do |name|
|
55
|
+
application_data.instance_variable_set(
|
56
|
+
name, instance_variable_get(name))
|
57
|
+
end
|
58
|
+
|
59
|
+
# Render view.
|
60
|
+
template = @@engine.get_template(view_name, view_options)
|
61
|
+
view_class = @@engine.get_view_class(view_name, view_options)
|
62
|
+
view = view_class.new()
|
63
|
+
view.set_model(application_data, locals)
|
64
|
+
output = ''
|
65
|
+
template.execute(view, output)
|
66
|
+
|
67
|
+
# Render layout.
|
68
|
+
layout_name = :layout
|
69
|
+
if options[:layout]
|
70
|
+
layout_name = options[:layout]
|
71
|
+
end
|
72
|
+
|
73
|
+
if layout_name != false
|
74
|
+
# If configured layout is true or nil, then use :layout.
|
75
|
+
if layout_name == true || !layout_name
|
76
|
+
layout_name = :layout
|
77
|
+
end
|
78
|
+
|
79
|
+
layout = @@engine.get_template(layout_name, view_options)
|
80
|
+
view_class = @@engine.get_view_class(layout_name, view_options)
|
81
|
+
view = view_class.new()
|
82
|
+
view.set_model(application_data, locals, { content: output })
|
83
|
+
layout_output = ''
|
84
|
+
layout.execute(view, layout_output)
|
85
|
+
output = layout_output
|
86
|
+
end
|
87
|
+
|
88
|
+
return output
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Called when this extension is registered.
|
93
|
+
def self.registered(app)
|
94
|
+
app.helpers Mullet::Sinatra::Helpers
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
Sinatra.register Mullet::Sinatra
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'mullet'
|
2
|
+
|
3
|
+
module Mullet; module Sinatra
|
4
|
+
|
5
|
+
# Loads view classes and template files.
|
6
|
+
class Engine
|
7
|
+
|
8
|
+
def initialize()
|
9
|
+
@class_cache = Hash.new()
|
10
|
+
@loader = Mullet::HTML::TemplateLoader.new(nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Gets template.
|
14
|
+
#
|
15
|
+
# @param [Symbol] view_name
|
16
|
+
# view name
|
17
|
+
# @param [Hash] options
|
18
|
+
# options
|
19
|
+
# @return template
|
20
|
+
def get_template(view_name, options)
|
21
|
+
template_path = options[:template_path] || options[:views]
|
22
|
+
@loader.template_path = template_path
|
23
|
+
return @loader.load("#{view_name.to_s()}.html")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Gets view class.
|
27
|
+
#
|
28
|
+
# @param [Symbol] view_name
|
29
|
+
# view name
|
30
|
+
# @param [Hash] options
|
31
|
+
# options
|
32
|
+
# @return view class
|
33
|
+
def get_view_class(view_name, options)
|
34
|
+
view_class = @class_cache.fetch(view_name, nil)
|
35
|
+
if view_class == nil
|
36
|
+
view_class = find_class(view_name.to_s(), options)
|
37
|
+
@class_cache.store(view_name, view_class)
|
38
|
+
end
|
39
|
+
return view_class
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# Gets the named view class.
|
45
|
+
#
|
46
|
+
# @param [String] view_name
|
47
|
+
# view name
|
48
|
+
# @param [Hash] options
|
49
|
+
# options
|
50
|
+
# @return view class, or `View` if not found
|
51
|
+
def find_class(view_name, options)
|
52
|
+
relative_view_path = options[:views]
|
53
|
+
if relative_view_path.start_with?(options[:root])
|
54
|
+
relative_view_path = relative_view_path[options[:root].size()..-1]
|
55
|
+
end
|
56
|
+
relative_view_path.sub!(/^\//, '')
|
57
|
+
|
58
|
+
# Construct string in form sub_folder/user_list
|
59
|
+
relative_view_name = File.join(relative_view_path, view_name)
|
60
|
+
|
61
|
+
# Convert view name from the format sub_folder/user_list to the format
|
62
|
+
# SubFolder::UserList
|
63
|
+
class_name = relative_view_name.split('/').map do |namespace|
|
64
|
+
namespace.split(/[-_]/).map do |part|
|
65
|
+
part[0] = part[0].chr.upcase
|
66
|
+
part
|
67
|
+
end.join
|
68
|
+
end.join('::')
|
69
|
+
|
70
|
+
# Is the class already defined?
|
71
|
+
if const = const_get!(class_name)
|
72
|
+
return const
|
73
|
+
end
|
74
|
+
|
75
|
+
full_view_name = File.join(options[:views], view_name)
|
76
|
+
if File.exists?("#{full_view_name}.rb")
|
77
|
+
require full_view_name
|
78
|
+
else
|
79
|
+
return View
|
80
|
+
end
|
81
|
+
|
82
|
+
if const = const_get!(class_name)
|
83
|
+
return const
|
84
|
+
end
|
85
|
+
return View
|
86
|
+
end
|
87
|
+
|
88
|
+
# Finds constant by fully qualified name.
|
89
|
+
#
|
90
|
+
# @param [String] name
|
91
|
+
# fully qualified name to find
|
92
|
+
# @return constant, or `nil` if not found
|
93
|
+
def const_get!(name)
|
94
|
+
name.split('::').inject(Object) do |cur_class, part|
|
95
|
+
cur_class.const_get(part)
|
96
|
+
end
|
97
|
+
rescue NameError
|
98
|
+
nil
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end; end
|
data/lib/mullet/version.rb
CHANGED
data/lib/mullet/view.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'mullet/default_nested_scope'
|
2
|
+
|
3
|
+
module Mullet
|
4
|
+
|
5
|
+
# Adapts model data for rendering in a template. Applications will typically
|
6
|
+
# define subclasses with attributes that will be referenced by name from the
|
7
|
+
# templates.
|
8
|
+
class View
|
9
|
+
|
10
|
+
# Sets model to adapt. Applications do not have to call this method
|
11
|
+
# directly. The template engine will call this method implicitly.
|
12
|
+
#
|
13
|
+
# @param data_objects
|
14
|
+
# scopes in outer to inner order
|
15
|
+
def set_model(*data_objects)
|
16
|
+
@model = DefaultNestedScope.new(*data_objects)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Resolves variable name to value from the model.
|
20
|
+
#
|
21
|
+
# @param [Symbol] name
|
22
|
+
# variable name
|
23
|
+
# @return variable value
|
24
|
+
def fetch(name)
|
25
|
+
return @model.get_variable_value(name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mullet
|
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:
|
12
|
+
date: 2012-04-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152575380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.6.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152575380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152574680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.5.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152574680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: redcarpet
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152574020 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.17.2
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152574020
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yard
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152573060 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,19 +54,20 @@ dependencies:
|
|
54
54
|
version: 0.7.3
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152573060
|
58
58
|
description: ! "It's like Mustache but the variables are in HTML attributes.\n\n *
|
59
59
|
Extremely simple variable syntax is incapable of expressing logic in the\n templates.\n
|
60
|
-
\ * Templates are clean HTML
|
61
|
-
|
60
|
+
\ * Templates are clean HTML which your HTML authoring tool and browser can\n display
|
61
|
+
correctly. You can use the templates as a static HTML prototype\n for your user
|
62
|
+
interface.\n"
|
62
63
|
email: pukkaone@gmail.com
|
63
64
|
executables: []
|
64
65
|
extensions: []
|
65
66
|
extra_rdoc_files: []
|
66
67
|
files:
|
67
68
|
- lib/mullet/container.rb
|
68
|
-
- lib/mullet/
|
69
|
-
- lib/mullet/
|
69
|
+
- lib/mullet/default_nested_scope.rb
|
70
|
+
- lib/mullet/default_scope.rb
|
70
71
|
- lib/mullet/html/attribute_command.rb
|
71
72
|
- lib/mullet/html/attributes.rb
|
72
73
|
- lib/mullet/html/command.rb
|
@@ -79,7 +80,6 @@ files:
|
|
79
80
|
- lib/mullet/html/layout.rb
|
80
81
|
- lib/mullet/html/message.rb
|
81
82
|
- lib/mullet/html/message_attribute_command.rb
|
82
|
-
- lib/mullet/html/model_attribute_command.rb
|
83
83
|
- lib/mullet/html/page_builder.rb
|
84
84
|
- lib/mullet/html/parser/attribute.rb
|
85
85
|
- lib/mullet/html/parser/constants.rb
|
@@ -89,17 +89,20 @@ files:
|
|
89
89
|
- lib/mullet/html/parser/simple_parser.rb
|
90
90
|
- lib/mullet/html/parser/tokenizer.rb
|
91
91
|
- lib/mullet/html/remove_mode.rb
|
92
|
+
- lib/mullet/html/scope_attribute_command.rb
|
92
93
|
- lib/mullet/html/static_text_renderer.rb
|
93
94
|
- lib/mullet/html/template.rb
|
94
95
|
- lib/mullet/html/template_builder.rb
|
95
96
|
- lib/mullet/html/template_loader.rb
|
96
97
|
- lib/mullet/html/template_parser.rb
|
97
98
|
- lib/mullet/html/unless_element_renderer.rb
|
98
|
-
- lib/mullet/model.rb
|
99
99
|
- lib/mullet/render_context.rb
|
100
|
+
- lib/mullet/scope.rb
|
101
|
+
- lib/mullet/sinatra/engine.rb
|
102
|
+
- lib/mullet/sinatra.rb
|
100
103
|
- lib/mullet/template_error.rb
|
101
|
-
- lib/mullet/tilt.rb
|
102
104
|
- lib/mullet/version.rb
|
105
|
+
- lib/mullet/view.rb
|
103
106
|
- lib/mullet.rb
|
104
107
|
homepage: http://pukkaone.github.com/mullet/
|
105
108
|
licenses: []
|
data/lib/mullet/tilt.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'mullet'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
# Registers the Mullet template engine in Tilt to handle file names with the
|
5
|
-
# `html` extension.
|
6
|
-
module Mullet; module Tilt
|
7
|
-
|
8
|
-
class MulletTemplate < ::Tilt::Template
|
9
|
-
|
10
|
-
def initialize_engine
|
11
|
-
@@loader = Mullet::HTML::TemplateLoader.new(nil)
|
12
|
-
@@parser = Mullet::HTML::TemplateParser.new(@@loader)
|
13
|
-
end
|
14
|
-
|
15
|
-
def prepare
|
16
|
-
if file
|
17
|
-
@@loader.template_path = File.dirname(file)
|
18
|
-
end
|
19
|
-
|
20
|
-
@template = @@parser.parse(data)
|
21
|
-
end
|
22
|
-
|
23
|
-
def evaluate(scope, locals, &block)
|
24
|
-
if block
|
25
|
-
content = block.call()
|
26
|
-
locals = locals.merge(content: content)
|
27
|
-
end
|
28
|
-
|
29
|
-
output = ''
|
30
|
-
@template.execute(DefaultNestedModel.new(scope, locals), output)
|
31
|
-
return output
|
32
|
-
end
|
33
|
-
|
34
|
-
::Tilt.register self, :html
|
35
|
-
end
|
36
|
-
|
37
|
-
end; end
|