Class: Bgem::Output::Exts::ERB::Default

Inherits:
Object
  • Object
show all
Includes:
Bgem::Output::Exts::ERB
Defined in:
lib/bgem.rb

Instance Attribute Summary

Attributes included from Bgem::Output::Ext::Common

#code, #dir, #file_extension, #name, #type

Instance Method Summary collapse

Methods included from Bgem::Output::Ext::Common

#ext, #initialize, #setup

Instance Method Details

#to_sObject



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/bgem.rb', line 205

def to_s
  <<~S
    module #{@name}
      class Context
        def env
          binding
        end
      end

      def self.[] params
        env = Context.new.env
        params.each do |name, value|
          env.local_variable_set name, value
        end

        template = <<~TEMPLATE
          #{@code}TEMPLATE

        require 'erb'
        renderer = ERB.new template
        renderer.result env
      end
    end
  S
end