summaryrefslogtreecommitdiff
path: root/lib/chef/deprecation
diff options
context:
space:
mode:
authorsersut <serdar@opscode.com>2013-05-30 13:38:32 -0700
committersersut <serdar@opscode.com>2013-05-30 13:44:50 -0700
commit32172b48de16b884a539ee4358b52d711f86b368 (patch)
tree79613bb71025a7a46f4b8ce8b868e6d56a628e44 /lib/chef/deprecation
parentaeee4bf96582769207780311b7b882c387656567 (diff)
downloadchef-32172b48de16b884a539ee4358b52d711f86b368.tar.gz
Make sure that windows line endings are protected during template rendering.
Diffstat (limited to 'lib/chef/deprecation')
-rw-r--r--lib/chef/deprecation/mixin/template.rb49
-rw-r--r--lib/chef/deprecation/provider/template.rb4
2 files changed, 51 insertions, 2 deletions
diff --git a/lib/chef/deprecation/mixin/template.rb b/lib/chef/deprecation/mixin/template.rb
new file mode 100644
index 0000000000..36d18ad90d
--- /dev/null
+++ b/lib/chef/deprecation/mixin/template.rb
@@ -0,0 +1,49 @@
+#
+# Author:: Serdar Sutay (<serdar@opscode.com>)
+# Copyright:: Copyright (c) 2013 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'tempfile'
+require 'erubis'
+
+class Chef
+ module Deprecation
+ module Mixin
+ # == Deprecation::Provider::Mixin::Template
+ # This module contains the deprecated functions of
+ # Chef::Mixin::Template. These functions are refactored to different
+ # components. They are frozen and will be removed in Chef 12.
+ #
+
+ module Template
+ def render_template(template, context)
+ begin
+ eruby = Erubis::Eruby.new(template)
+ output = eruby.evaluate(context)
+ rescue Object => e
+ raise TemplateError.new(e, template, context)
+ end
+ Tempfile.open("chef-rendered-template") do |tempfile|
+ tempfile.print(output)
+ tempfile.close
+ yield tempfile
+ end
+ end
+ end
+ end
+ end
+end
+
diff --git a/lib/chef/deprecation/provider/template.rb b/lib/chef/deprecation/provider/template.rb
index 0f93c637f6..3d8071f00b 100644
--- a/lib/chef/deprecation/provider/template.rb
+++ b/lib/chef/deprecation/provider/template.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-require 'chef/mixin/template'
+require 'chef/deprecation/mixin/template'
class Chef
module Deprecation
@@ -29,7 +29,7 @@ class Chef
#
module Template
- include Chef::Mixin::Template
+ include Chef::Deprecation::Mixin::Template
def template_finder
@template_finder ||= begin