-
-
Save simongareste/d32b8bc6abac4db052159f222d2d50a6 to your computer and use it in GitHub Desktop.
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
source "https://rubygems.org" | |
ruby "2.4.0" | |
#gem 'dry-view', "~> 0.2.2" | |
gem 'dry-view', "~> 0.3.0" | |
gem 'logger' | |
gem 'json' | |
gem 'tilt' | |
gem 'tilt-handlebars' | |
gem 'orstruct' |
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
require_relative './templater' | |
options = {:context => OpenStruct.new('name':'John', 'email':'john@doe.com'), :lang => 'en-GB', :template => 'basictemplate'} | |
Communication::Template::Templater.new(options) |
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
require 'dry-view' | |
require 'logger' | |
require 'json' | |
require_relative './templater_view' | |
module Communication | |
module Template | |
class Templater | |
def initialize(options) | |
view = TemplaterView.new(options[:template]) | |
rendered_body = view.(:context => options[:context], :format => "#{options[:lang]}.body") | |
puts rendered_body | |
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
module Communication | |
module Template | |
class TemplaterView < Dry::View::Controller | |
attr_writer :template_path | |
configure do |config| | |
config.paths = ["#{__dir__}"] | |
end | |
def initialize(template_path) | |
super() | |
@template_path = template_path | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment