Skip to content

Instantly share code, notes, and snippets.

@simongareste
Last active Jul 26, 2017
Embed
What would you like to do?
hello {{name}}.
Your email is {{email}}.
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'
require_relative './templater'
options = {:context => OpenStruct.new('name':'John', 'email':'john@doe.com'), :lang => 'en-GB', :template => 'basictemplate'}
Communication::Template::Templater.new(options)
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
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