Skip to content

Instantly share code, notes, and snippets.

@simongareste
Last active July 26, 2017 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simongareste/d32b8bc6abac4db052159f222d2d50a6 to your computer and use it in GitHub Desktop.
Save simongareste/d32b8bc6abac4db052159f222d2d50a6 to your computer and use it in GitHub Desktop.
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