Sha256: caec2fedaba293d77f1efb2fa03b8e108e7fa4d9f9bc3d83b802d9ddaa7f5cdb
Contents?: true
Size: 1.66 KB
Versions: 32
Compression:
Stored size: 1.66 KB
Contents
class Card module Mod # ModuleTemplate is an abstract class to build ruby modules out of # deckos dsl for sets and set patterns. # {SetModule} and {PatternTemplate} inherit from it and adapt the template # to their needs. class ModuleTemplate def initialize modules, content_path modules = Array.wrap modules @pattern = modules.shift @modules = modules @content = ::File.read content_path @content_path = content_path end # Evaluates the module in the top level namespace. def build eval to_s, TOPLEVEL_BINDING, @content_path, offset end # @return [String] the ruby code to build the modal def to_s return content_with_source_comment if simple_load? wrap_with_module_def end # Just run the code of the source. # Don't use the path to the file as module hierarchy. def simple_load? @content =~ /\A#!\s?simple load/ end private def preamble "" end def postamble "" end def wrap_with_module_def # for unknown reasons strip_heredoc doesn't work properly # and with trailing whitespace code like `=begin` fails <<-RUBY.strip_heredoc # -*- encoding : utf-8 -*- #{module_chain} #{preamble} #{content_with_source_comment} #{postamble} #{end_chain} RUBY end def content_with_source_comment <<-RUBY.strip_heredoc # ~~ above autogenerated; below pulled from #{@content_path} ~~ #{@content} # ~~ below autogenerated; above pulled from #{@content_path} ~~ RUBY end end end end
Version data entries
32 entries across 32 versions & 1 rubygems