-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #667 from yast/erb_template
Erb template
- Loading branch information
Showing
5 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "yast" | ||
require "erb" | ||
|
||
module Y2Autoinstallation | ||
class Y2ERB | ||
def self.render(path) | ||
env = TemplateEnvironment.new | ||
template = ERB.new(File.read(path)) | ||
template.result(env.public_binding) | ||
end | ||
|
||
class TemplateEnvironment | ||
def hardware | ||
@hardware ||= Yast::SCR.Read(Yast::Path.new(".probe")) | ||
end | ||
|
||
# expose method bindings | ||
def public_binding | ||
binding | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) [2020] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "../test_helper" | ||
|
||
require "tempfile" | ||
require "autoinstall/y2erb" | ||
|
||
describe Y2Autoinstallation::Y2ERB do | ||
describe ".render" do | ||
it "returns string with rendered template" do | ||
# mock just for optimization | ||
allow(Yast::SCR).to receive(:Read).and_return({}) | ||
file = Tempfile.new("test") | ||
path = file.path | ||
file.write("<test><%= hardware.inspect %></test>") | ||
file.close | ||
result = described_class.render(path) | ||
file.unlink | ||
|
||
expect(result).to match(/<test>{.*}<\/test>/) | ||
end | ||
end | ||
end |