rad_core 0.2.6 → 0.2.7

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.
Files changed (167) hide show
  1. data/Rakefile +2 -2
  2. data/bin/rad +20 -25
  3. data/lib/components/config.rb +1 -1
  4. data/lib/components/configurators.rb +2 -2
  5. data/lib/components/controller.rb +2 -2
  6. data/lib/components/conveyors.rb +2 -2
  7. data/lib/components/environment.rb +1 -1
  8. data/lib/components/environment.yml +28 -28
  9. data/lib/components/flash.rb +1 -1
  10. data/lib/components/html.rb +1 -1
  11. data/lib/components/http.rb +1 -1
  12. data/lib/components/http.yml +1 -1
  13. data/lib/components/logger.rb +2 -2
  14. data/lib/components/mailer.rb +2 -2
  15. data/lib/components/remote.rb +1 -1
  16. data/lib/components/router.rb +3 -3
  17. data/lib/components/template.rb +2 -2
  18. data/lib/components/web.rb +3 -3
  19. data/lib/rad.rb +1 -1
  20. data/lib/rad/_support/active_support.rb +7 -7
  21. data/lib/rad/_support/active_support/locales/ru/actionview.yml +8 -8
  22. data/lib/rad/_support/active_support/locales/ru/activesupport.yml +4 -4
  23. data/lib/rad/_support/active_support/locales/ru/datetime.yml +5 -5
  24. data/lib/rad/_support/active_support/time.rb +2 -2
  25. data/lib/rad/_support/addressable.rb +6 -6
  26. data/lib/rad/_support/class_loader.rb +1 -1
  27. data/lib/rad/_support/extensions.rb +5 -5
  28. data/lib/rad/_support/filters.rb +13 -13
  29. data/lib/rad/_support/hacks_and_fixes.rb +5 -5
  30. data/lib/rad/_support/mime.rb +4 -4
  31. data/lib/rad/_support/module.rb +11 -11
  32. data/lib/rad/_support/require.rb +5 -5
  33. data/lib/rad/_support/rson.rb +4 -4
  34. data/lib/rad/_support/string.rb +9 -9
  35. data/lib/rad/cli/helper.rb +5 -5
  36. data/lib/rad/configurators/_require.rb +2 -2
  37. data/lib/rad/configurators/abstract.rb +5 -5
  38. data/lib/rad/configurators/web.rb +8 -8
  39. data/lib/rad/controller/_abstract.rb +15 -14
  40. data/lib/rad/controller/_abstract/miscellaneous.rb +5 -5
  41. data/lib/rad/controller/_abstract/render.rb +40 -40
  42. data/lib/rad/controller/_abstract/responder.rb +1 -1
  43. data/lib/rad/controller/_context.rb +1 -1
  44. data/lib/rad/controller/_http.rb +11 -11
  45. data/lib/rad/controller/_require.rb +6 -6
  46. data/lib/rad/controller/processors/controller_caller.rb +3 -3
  47. data/lib/rad/controller/processors/controller_error_handling.rb +14 -14
  48. data/lib/rad/controller/processors/controller_logger.rb +1 -1
  49. data/lib/rad/conveyors/_conveyor.rb +9 -9
  50. data/lib/rad/conveyors/_conveyors.rb +4 -4
  51. data/lib/rad/conveyors/_params.rb +5 -5
  52. data/lib/rad/conveyors/_processor.rb +2 -2
  53. data/lib/rad/conveyors/_workspace.rb +5 -5
  54. data/lib/rad/conveyors/processors/conveyor_logger.rb +3 -3
  55. data/lib/rad/environment/_config.rb +4 -4
  56. data/lib/rad/environment/_environment.rb +10 -10
  57. data/lib/rad/environment/_files_helper.rb +5 -5
  58. data/lib/rad/environment/_logger.rb +9 -9
  59. data/lib/rad/environment/_require.rb +4 -4
  60. data/lib/rad/gems.rb +14 -14
  61. data/lib/rad/html/_flash.rb +5 -5
  62. data/lib/rad/html/_helpers/basic_html_helper.rb +12 -12
  63. data/lib/rad/html/_helpers/form_helper.rb +19 -19
  64. data/lib/rad/html/_helpers/javascript_helper.rb +6 -6
  65. data/lib/rad/html/_helpers/model_helper.rb +17 -17
  66. data/lib/rad/html/_require.rb +1 -1
  67. data/lib/rad/html/processors/prepare_flash.rb +3 -3
  68. data/lib/rad/html/processors/scoped_params.rb +4 -4
  69. data/lib/rad/http/_http.rb +4 -4
  70. data/lib/rad/http/_http_adapter.rb +5 -5
  71. data/lib/rad/http/_request.rb +11 -11
  72. data/lib/rad/http/_require.rb +8 -8
  73. data/lib/rad/http/_response.rb +5 -5
  74. data/lib/rad/http/_support/rack/fixes.rb +3 -3
  75. data/lib/rad/http/_support/rack/rack_adapter.rb +5 -5
  76. data/lib/rad/http/processors/evaluate_format.rb +4 -4
  77. data/lib/rad/http/processors/http_logger.rb +3 -3
  78. data/lib/rad/http/processors/http_writer.rb +7 -7
  79. data/lib/rad/http/processors/prepare_params.rb +5 -5
  80. data/lib/rad/mailer/_letter.rb +1 -1
  81. data/lib/rad/mailer/_mailer.rb +1 -1
  82. data/lib/rad/mailer/_mailer_controller.rb +6 -6
  83. data/lib/rad/mailer/_require.rb +1 -1
  84. data/lib/rad/mailer/processors/letter_builder.rb +6 -6
  85. data/lib/rad/profiles/mailer.rb +2 -2
  86. data/lib/rad/profiles/web.rb +13 -13
  87. data/lib/rad/remote/processors/remote_caller.rb +10 -10
  88. data/lib/rad/remote/processors/remote_logger.rb +1 -1
  89. data/lib/rad/router/_abstract_router.rb +9 -9
  90. data/lib/rad/router/_alias_router.rb +34 -34
  91. data/lib/rad/router/_basic_router.rb +12 -12
  92. data/lib/rad/router/_configurator.rb +6 -6
  93. data/lib/rad/router/_core_routing_helper.rb +4 -4
  94. data/lib/rad/router/_object_router.rb +45 -45
  95. data/lib/rad/router/_require.rb +8 -8
  96. data/lib/rad/router/_restful_router.rb +25 -25
  97. data/lib/rad/router/_router.rb +78 -78
  98. data/lib/rad/router/_simple_router.rb +5 -5
  99. data/lib/rad/router/processors/router.rb +6 -6
  100. data/lib/rad/spec/controller.rb +9 -9
  101. data/lib/rad/spec/environment.rb +7 -7
  102. data/lib/rad/spec/http.rb +2 -2
  103. data/lib/rad/spec/http_controller.rb +22 -22
  104. data/lib/rad/spec/mailer.rb +4 -4
  105. data/lib/rad/spec/remote.rb +1 -1
  106. data/lib/rad/spec/router.rb +4 -4
  107. data/lib/rad/spec/template.rb +2 -2
  108. data/lib/rad/tasks.rb +2 -2
  109. data/lib/rad/template/_context.rb +15 -15
  110. data/lib/rad/template/_relative_path_resolver.rb +1 -1
  111. data/lib/rad/template/_support/tilt.rb +17 -17
  112. data/lib/rad/template/_support/tilt_fixes.rb +3 -3
  113. data/lib/rad/template/_template.rb +47 -47
  114. data/lib/rad/web/_ajax_helper.rb +4 -4
  115. data/lib/rad/web/_controller_miscellaneous_helper.rb +5 -5
  116. data/lib/rad/web/_ensure_no_www.rb +5 -5
  117. data/lib/rad/web/_protect_from_forgery.rb +18 -18
  118. data/lib/rad/web/_require.rb +7 -7
  119. data/lib/rad/web/_router/abstract_routing_helper.rb +4 -4
  120. data/lib/rad/web/_router/controller_routing_helper.rb +15 -15
  121. data/lib/rad/web/_router/view_routing_helper.rb +12 -12
  122. data/readme.md +5 -5
  123. data/spec/controller/abstract_spec.rb +29 -29
  124. data/spec/controller/context_spec.rb +32 -32
  125. data/spec/controller/error_handling_spec.rb +31 -31
  126. data/spec/controller/helper_spec.rb +13 -13
  127. data/spec/controller/http_spec.rb +32 -32
  128. data/spec/controller/render_spec.rb +59 -59
  129. data/spec/conveyors/conveyors_spec.rb +32 -32
  130. data/spec/environment/config_spec.rb +6 -6
  131. data/spec/environment/environment_spec.rb +7 -7
  132. data/spec/environment/minimal_app_spec.rb +4 -4
  133. data/spec/environment/standard_app_spec.rb +10 -10
  134. data/spec/html/basic_html_helper_spec.rb +6 -6
  135. data/spec/html/form_helper_spec.rb +5 -5
  136. data/spec/html/javascript_helper_spec.rb +4 -4
  137. data/spec/html/model_helper_spec.rb +12 -12
  138. data/spec/html/scoped_params_spec.rb +2 -2
  139. data/spec/html/spec_helper.rb +3 -3
  140. data/spec/http/http_spec.rb +9 -9
  141. data/spec/http/miscellaneous_spec.rb +2 -2
  142. data/spec/mailer/mail_controller_spec.rb +23 -23
  143. data/spec/remote/remote_spec.rb +26 -26
  144. data/spec/router/alias_router_spec.rb +22 -22
  145. data/spec/router/basic_router_spec.rb +8 -8
  146. data/spec/router/configurator_spec.rb +4 -4
  147. data/spec/router/integration_spec.rb +17 -17
  148. data/spec/router/object_router_spec.rb +47 -47
  149. data/spec/router/persistent_params_spec.rb +18 -18
  150. data/spec/router/restful_router_spec.rb +39 -39
  151. data/spec/router/router_spec.rb +37 -37
  152. data/spec/router/routing_helper_spec.rb +18 -18
  153. data/spec/support/filters_spec.rb +11 -13
  154. data/spec/template/template_spec.rb +43 -45
  155. data/spec/template/template_spec/views/layout/content_for/content.erb +3 -1
  156. data/spec/template/template_spec/views/layout/content_for/layout.erb +1 -1
  157. data/spec/template/tilt_spec.rb +24 -24
  158. data/spec/web/basic_spec.rb +25 -25
  159. data/spec/web/controller_routing_helper_spec.rb +26 -26
  160. data/spec/web/flash_spec.rb +31 -31
  161. data/spec/web/protect_from_forgery_spec.rb +44 -44
  162. data/spec/web/spec_helper_spec.rb +16 -16
  163. data/spec/web/view_routing_helper_spec.rb +31 -31
  164. metadata +46 -49
  165. data/lib/rad/_support/callbacks.rb +0 -166
  166. data/lib/rad/_support/ruby_ext_with_active_support.rb +0 -4
  167. data/spec/support/callbacks_spec.rb +0 -157
@@ -3,7 +3,7 @@ rspec do
3
3
  before do
4
4
  $with_prepare_params = true
5
5
  end
6
-
6
+
7
7
  after do
8
8
  $with_prepare_params = false
9
9
  end
@@ -11,7 +11,7 @@ rspec do
11
11
  end
12
12
 
13
13
  rad.before_scope :cycle do
14
- unless $with_prepare_params
14
+ unless $with_prepare_params
15
15
  rad.conveyors.web do |web|
16
16
  web.definitions.delete_if{|pdef, args| pdef.name =~ /PrepareParams/}
17
17
  web.build!
@@ -10,63 +10,63 @@ rspec do
10
10
  def request
11
11
  rad.workspace.request
12
12
  end
13
-
13
+
14
14
  # def self.with_http_controller options = {}
15
15
  # scope = options[:before] || :all
16
16
  # prepare_params = options[:prepare_params]
17
- #
17
+ #
18
18
  # with_controller options
19
- #
19
+ #
20
20
  # unless prepare_params
21
21
  # before scope do
22
- #
23
- # end
22
+ #
23
+ # end
24
24
  # end
25
25
  # end
26
-
26
+
27
27
  WCALL_OPTIONS = [:controller]
28
28
  attr_writer :wcall_options
29
29
  def wcall_options; @wcall_options ||= {} end
30
-
30
+
31
31
  def set_wcall options
32
32
  invalid_options = options.keys - WCALL_OPTIONS
33
33
  raise "Unsupported options #{invalid_options}!" unless invalid_options.empty?
34
-
34
+
35
35
  self.wcall_options = options
36
36
  end
37
-
37
+
38
38
  def set_controller controller_class
39
39
  @controller_class = controller_class
40
40
  set_wcall controller: controller_class
41
41
  end
42
-
42
+
43
43
  def self.set_controller controller_class
44
44
  before{set_controller controller_class}
45
45
  end
46
-
46
+
47
47
  def wcall *args, &block
48
- workspace_variables, params = parse_wcall_arguments *args
48
+ workspace_variables, params = parse_wcall_arguments *args
49
49
  ccall nil, nil, params, workspace_variables, &block
50
50
  end
51
-
51
+
52
52
  def post_wcall *args, &block
53
53
  params = args.extract_options!
54
54
  raise "_method variable already set!" if params.include?(:_method) or params.include?('_method')
55
55
  wcall(*(args << params.merge(_method: 'post')), &block)
56
56
  end
57
-
57
+
58
58
  protected
59
- def parse_wcall_arguments *args
59
+ def parse_wcall_arguments *args
60
60
  # parsing params
61
61
  params = args.extract_options!
62
62
  first = args.first
63
63
 
64
- workspace_variables = {}
64
+ workspace_variables = {}
65
65
  if args.size == 1 and first.is_a?(String) and first =~ /^\/|^http:/
66
- uri = Uri.parse first
66
+ uri = Uri.parse first
67
67
  workspace_variables[:path] = uri.path
68
68
  workspace_variables[:env] = Rad::Http::Request.stub_environment(first)
69
-
69
+
70
70
  # some params may be defined in :url ans some in :params, merging both
71
71
  params = uri.query_values.merge params if uri.query_values
72
72
  elsif (first.is_a?(String) or first.is_a?(Symbol)) and args.size <= 2
@@ -77,7 +77,7 @@ rspec do
77
77
  elsif first.is_a?(Class) and args.size <= 3
78
78
  workspace_variables[:path] = '/'
79
79
  workspace_variables[:class] = args[0]
80
- workspace_variables[:method_name] = args[1]
80
+ workspace_variables[:method_name] = args[1]
81
81
  workspace_variables.merge! args[2] if args.size > 2
82
82
  else
83
83
  raise "Invalid input!"
@@ -85,7 +85,7 @@ rspec do
85
85
 
86
86
  # preparing environment
87
87
  workspace_variables[:env] ||= {}
88
- workspace_variables[:env].reverse_merge! Rad::Http::Request.stub_environment
88
+ workspace_variables[:env].reverse_merge! Rad::Http::Request.stub_environment
89
89
 
90
90
  # setting request method
91
91
  if request_method = params.delete(:_method) || params.delete('_method')
@@ -94,9 +94,9 @@ rspec do
94
94
  raise "REQUEST_METHOD variable already set!" if workspace_variables[:env].include? 'REQUEST_METHOD'
95
95
  workspace_variables[:env]['REQUEST_METHOD'] = request_method
96
96
  end
97
-
97
+
98
98
  workspace_variables[:request] = Rad::Http::Request.new(workspace_variables[:env])
99
-
99
+
100
100
  return workspace_variables, params
101
101
  end
102
102
  end
@@ -2,16 +2,16 @@ module Rad::MailerSpecHelper
2
2
  def sent_letters
3
3
  Rad::MailerSpecHelper.sent_letters
4
4
  end
5
-
5
+
6
6
  class << self
7
7
  attr_accessor :sent_letters
8
- end
8
+ end
9
9
  end
10
10
 
11
11
  rspec.include Rad::MailerSpecHelper
12
12
 
13
- RSpec.configure do |config|
14
- config.before do
13
+ RSpec.configure do |config|
14
+ config.before do
15
15
  Rad::MailerSpecHelper.sent_letters = []
16
16
  end
17
17
  end
@@ -1,7 +1,7 @@
1
1
  require 'rad'
2
2
 
3
3
  rspec do
4
- def rcall klass, method, params = {}
4
+ def rcall klass, method, params = {}
5
5
  rad.conveyors.services.call(
6
6
  class: klass, method_name: method, params: Rad::Conveyors::Params.new(params)
7
7
  )
@@ -1,13 +1,13 @@
1
1
  rspec.include Rad::Router::CoreRoutingHelper
2
2
 
3
3
  # rspec do
4
- # def self.with_router options = {}
4
+ # def self.with_router options = {}
5
5
  # scope = options[:before] || :all
6
- #
6
+ #
7
7
  # before scope do
8
- #
8
+ #
9
9
  # end
10
- # end
10
+ # end
11
11
  # end
12
12
 
13
13
  rspec.define_matcher :redirect_to do |actual, expected|
@@ -5,12 +5,12 @@ rspec do
5
5
  else
6
6
  args
7
7
  end
8
-
8
+
9
9
  before do
10
10
  rad.template
11
11
  list.each{|path| rad.template.paths << path}
12
12
  end
13
-
13
+
14
14
  after do
15
15
  list.each{|path| rad.template.paths.delete path}
16
16
  end
@@ -4,10 +4,10 @@ require 'ruby_ext'
4
4
  task :environment do
5
5
  require 'rad'
6
6
  rad.mode = ENV['m'] || ENV['mode'] || ENV['env'] || ENV['environment'] || :development
7
-
7
+
8
8
  require 'rad/cli/helper'
9
9
  Rad::Cli::Helper.use_runtime_path!
10
-
10
+
11
11
  rad.runtime_path = File.expand_path '.'
12
12
 
13
13
  load "./init.rb"
@@ -1,22 +1,22 @@
1
1
  class Rad::Template::Context
2
2
  include Tilt::CompileSite, Tilt::ContextExt
3
3
 
4
- #
4
+ #
5
5
  # System
6
6
  #
7
7
  attr_accessor :_tilt_template
8
-
8
+
9
9
  def initialize instance_variables = nil
10
10
  set_instance_variables! instance_variables if instance_variables
11
- end
12
-
11
+ end
12
+
13
13
  # for saving :format, :current_dir and others
14
14
  attr_accessor :scope_variables
15
15
 
16
16
 
17
- #
17
+ #
18
18
  # Helpers
19
- #
19
+ #
20
20
  inject(
21
21
  workspace: :workspace,
22
22
  router: :router,
@@ -25,13 +25,13 @@ class Rad::Template::Context
25
25
  )
26
26
 
27
27
  delegate :render, to: :template
28
- delegate :url_for, to: :router
28
+ delegate :url_for, to: :router
29
29
 
30
30
 
31
31
  def j obj
32
32
  obj.to_s.json_escape
33
33
  end
34
-
34
+
35
35
  def blank? obj
36
36
  obj.is_a?(String) ? !!(obj =~ /\A\s*\z/) : obj.blank?
37
37
  end
@@ -40,16 +40,16 @@ class Rad::Template::Context
40
40
  end
41
41
 
42
42
 
43
- #
43
+ #
44
44
  # Content Variables
45
- #
45
+ #
46
46
  attr_accessor :content_block
47
- def content_variables; @content_variables ||= {}.to_openobject end
47
+ def content_variables; @content_variables ||= {}.to_openobject end
48
48
  def content_for name, content = nil, &block
49
49
  content ||= capture(&block)
50
50
  (content_variables[name.to_s] ||= "") << content
51
51
  nil
52
- end
52
+ end
53
53
  def prepend_to name, content = nil, &block
54
54
  content ||= capture(&block)
55
55
  (content_variables[name.to_s] ||= "").insert 0, content
@@ -64,15 +64,15 @@ class Rad::Template::Context
64
64
  def has_content_for? name
65
65
  content_variables.include? name.to_s
66
66
  end
67
-
67
+
68
68
  def find_relative_template *args
69
69
  self.class.find_relative_template *args
70
70
  end
71
-
71
+
72
72
  protected
73
73
  def set_instance_variables! instance_variables
74
74
  instance_variables = [instance_variables] unless instance_variables.is_a? Array
75
- instance_variables.each do |container|
75
+ instance_variables.each do |container|
76
76
  if container.is_a? Hash
77
77
  container.each do |name, value|
78
78
  instance_variable_set("@#{name}", value)
@@ -1,5 +1,5 @@
1
1
  class Rad::Template::RelativePathResolver
2
- def find_relative_template tname, prefixes, format, exact_format, current_dir
2
+ def find_relative_template tname, prefixes, format, exact_format, current_dir
3
3
  raise "You can't use relative template path '#{tname}' without :current_dir!" unless current_dir
4
4
  prefixes = prefixes || rad.template.prefixes
5
5
  rad.template.find_file("/#{tname}", prefixes, format, exact_format, [current_dir])
@@ -1,40 +1,40 @@
1
1
  module Tilt
2
- #
2
+ #
3
3
  # Include it into your template context class for :output, :capture and :concat support
4
- #
4
+ #
5
5
  module ContextExt
6
6
  def output
7
7
  _tilt_template.class.output(self)
8
8
  end
9
-
9
+
10
10
  def capture *args, &block
11
- _tilt_template.class.capture self, &block
11
+ _tilt_template.class.capture self, &block
12
12
  end
13
-
13
+
14
14
  def concat value
15
15
  _tilt_template.class.concat self, value
16
16
  end
17
- end
18
-
17
+ end
18
+
19
19
  class Template
20
20
  def self.get_output context
21
21
  raise "Output variable for #{self.class} not defined!"
22
22
  end
23
-
23
+
24
24
  def self.capture context, &block
25
25
  raise "capture not implemented for #{self.class}!"
26
26
  end
27
-
27
+
28
28
  def self.concat context, value
29
29
  raise "concat not implemented for #{self.class}!"
30
30
  end
31
31
  end
32
-
32
+
33
33
  class ERBTemplate
34
34
  def self.get_output context
35
35
  context.instance_variable_get "@output"
36
36
  end
37
-
37
+
38
38
  def self.capture context, &block
39
39
  begin
40
40
  old_output = context.instance_variable_get "@output"
@@ -44,23 +44,23 @@ module Tilt
44
44
  context.instance_variable_get "@output"
45
45
  ensure
46
46
  context.instance_variable_set "@output", old_output
47
- end
47
+ end
48
48
  end
49
-
49
+
50
50
  def self.concat context, value
51
51
  get_output(context) << value
52
- end
52
+ end
53
53
  end
54
-
54
+
55
55
  class HamlTemplate
56
56
  def self.get_output context
57
57
  context.haml_buffer.buffer
58
58
  end
59
-
59
+
60
60
  def self.capture context, &block
61
61
  context.capture_haml &block
62
62
  end
63
-
63
+
64
64
  def self.concat context, value
65
65
  context.haml_concat value
66
66
  end
@@ -1,13 +1,13 @@
1
- #
1
+ #
2
2
  # Tilt::HamlTemplate.inspect causes error, fixin it.
3
- #
3
+ #
4
4
  class Tilt::HamlTemplate
5
5
  def inspect
6
6
  "#<Tilt::HamlTemplate:#{object_id} ...>"
7
7
  end
8
8
  end
9
9
 
10
- #
10
+ #
11
11
  # Tilt::HamlTemplate.inspect causes error, fixin it.
12
12
  #
13
13
  class Haml::Buffer
@@ -3,72 +3,72 @@ class Rad::Template
3
3
 
4
4
  attr_accessor :relative_path_resolver, :prefixes
5
5
  attr_required :prefixes
6
-
6
+
7
7
  def initialize
8
8
  @relative_path_resolver = RelativePathResolver.new
9
9
  end
10
-
10
+
11
11
  def render *args, &block
12
12
  result, context = basic_render(parse_arguments(*args), &block)
13
13
  result
14
- end
15
-
14
+ end
15
+
16
16
  def exist? tname, options = {}
17
17
  !!find_template(tname, options)
18
18
  end
19
-
19
+
20
20
  def read tname, options = {}
21
21
  file = find_template(tname, options) || raise("no template '#{tname}'!")
22
22
  File.read file
23
23
  end
24
-
24
+
25
25
  def basic_render options, &block
26
26
  with_context options do |context|
27
27
  context.content_block ||= block
28
28
 
29
- with_scope options, context do |scope|
29
+ with_scope options, context do |scope|
30
30
  file = (
31
- options[:file] ||
31
+ options[:file] ||
32
32
  find_template(options[:template], options.merge(scope)) ||
33
33
  (options[:if_not_exist] && find_template(options[:if_not_exist], options.merge(scope))) ||
34
34
  raise("no template '#{options[:template]}'!")
35
35
  )
36
-
36
+
37
37
  scope[:current_dir] = dirname(file)
38
-
38
+
39
39
  template = create_tilt_template file
40
-
40
+
41
41
  result = with_template context, template do
42
42
  render_template template, context, options, &context.content_block
43
43
  end
44
-
44
+
45
45
  return result, context
46
- end
46
+ end
47
47
  end
48
48
  end
49
-
49
+
50
50
  def parse_arguments *args
51
51
  options = args.extract_options!
52
52
  if args.size == 1
53
53
  options[:template] = args.first
54
- else
54
+ else
55
55
  raise "Invalid input" if args.size != 0
56
- end
56
+ end
57
57
 
58
58
  options
59
59
  end
60
-
60
+
61
61
  def find_file tname, prefixes, format, exact_format, directories
62
62
  prefixes = prefixes || self.prefixes
63
63
  prefixes.each do |prefix|
64
64
  tname = template_name_with_prefix("#{directory_name}#{tname}", prefix)
65
65
  file = if tname.include? '.'
66
66
  _find_file(tname, directories) || _find_file("#{tname}.*", directories)
67
- else
67
+ else
68
68
  if format
69
69
  _find_file("#{tname}.#{format}.*", directories) or
70
70
  _find_file("#{tname}.*", directories, exact_format)
71
- else
71
+ else
72
72
  _find_file("#{tname}.*", directories)
73
73
  end
74
74
  end
@@ -76,40 +76,40 @@ class Rad::Template
76
76
  end
77
77
  return nil
78
78
  end
79
-
79
+
80
80
  def directory_name; "" end
81
-
81
+
82
82
  def paths; @paths ||= [] end
83
-
84
- protected
85
- # with_one_extension - 'tname.*' matches not only 'tname.erb' but also 'tname.html.erb',
83
+
84
+ protected
85
+ # with_one_extension - 'tname.*' matches not only 'tname.erb' but also 'tname.html.erb',
86
86
  # with this option enabled it will not match 'tname.html.erb', only 'tname.erb'
87
- def _find_file pattern, directories, with_one_extension = false
87
+ def _find_file pattern, directories, with_one_extension = false
88
88
  files = rad.environment.find_files_by_pattern_without_cache pattern, directories
89
- files = files.select{|f| f !~ /\.[^\.\/]+\.[^\.\/]+$/} if with_one_extension
89
+ files = files.select{|f| f !~ /\.[^\.\/]+\.[^\.\/]+$/} if with_one_extension
90
90
  raise "multiple templates for '#{pattern}'!" if files.size > 1
91
- files.first
91
+ files.first
92
92
  end
93
-
94
- def template_name_with_prefix tname, prefix
93
+
94
+ def template_name_with_prefix tname, prefix
95
95
  index = tname.rindex('/')
96
96
  index = index ? index + 1 : 0
97
97
  tname = tname.clone
98
98
  tname.insert index, prefix
99
99
  end
100
-
100
+
101
101
  def with_context options, &block
102
102
  context = Thread.current[:render_context] || options[:context] || Context.new(options[:instance_variables])
103
-
103
+
104
104
  old = Thread.current[:render_context]
105
- begin
105
+ begin
106
106
  Thread.current[:render_context] = context
107
107
  block.call context
108
108
  ensure
109
109
  Thread.current[:render_context] = old
110
110
  end
111
111
  end
112
-
112
+
113
113
  def with_scope options, context, &block
114
114
  initial = context.scope_variables
115
115
 
@@ -126,22 +126,22 @@ class Rad::Template
126
126
  context.scope_variables = old if initial
127
127
  end
128
128
  end
129
-
129
+
130
130
  def with_template context, template, &block
131
131
  old = context._tilt_template
132
- begin
132
+ begin
133
133
  context._tilt_template = template
134
134
  block.call context
135
135
  ensure
136
136
  context._tilt_template = old
137
137
  end
138
138
  end
139
-
140
- def dirname path;
139
+
140
+ def dirname path;
141
141
  File.dirname path
142
- end
143
- cache_method_with_params_in_production :dirname
144
-
142
+ end
143
+ cache_method_with_params_in_production :dirname
144
+
145
145
  def find_template tname, options
146
146
  tname.must_be.a String
147
147
  # splitted into two to optimize cache
@@ -152,18 +152,18 @@ class Rad::Template
152
152
  resolver.find_relative_template tname, options[:prefixes], options[:format], options[:exact_format], options[:current_dir]
153
153
  end
154
154
  end
155
-
156
- def find_absolute_template tname, prefixes, format, exact_format
155
+
156
+ def find_absolute_template tname, prefixes, format, exact_format
157
157
  prefixes = prefixes || self.prefixes
158
158
  find_file(tname, prefixes, format, exact_format, paths)
159
159
  end
160
- cache_method_with_params_in_production :find_absolute_template
161
-
162
- def create_tilt_template path
160
+ cache_method_with_params_in_production :find_absolute_template
161
+
162
+ def create_tilt_template path
163
163
  Tilt.new(path, nil, ugly: true, outvar: "@output"){|t| File.read(t.file)}
164
164
  end
165
165
  cache_method_with_params_in_production :create_tilt_template
166
-
166
+
167
167
  def render_template template, context, options, &block
168
168
  locals = options[:locals] || {}
169
169
  if object = options[:object]
@@ -171,5 +171,5 @@ class Rad::Template
171
171
  end
172
172
 
173
173
  template.render context, locals, &block
174
- end
174
+ end
175
175
  end