Class: Card::Mod::Loader::SetLoader::Template
Instance Method Summary
collapse
#build, #simple_load?, #to_s
Constructor Details
#initialize(modules, content_path, strategy) ⇒ Template
Returns a new instance of Template.
34
35
36
37
|
# File 'lib/card/mod/loader/set_loader.rb', line 34
def initialize modules, content_path, strategy
super
@modules.pop if helper_module?
end
|
Instance Method Details
54
55
56
57
58
59
60
61
|
# File 'lib/card/mod/loader/set_loader.rb', line 54
def add_explicit_format_modules
@content.gsub!(/^ *format +:?(\w+)? *do *$/) do
format_name = $1.blank? ? nil : $1.to_sym
"module #{module_name format_name}; " \
"parent.send :register_set_format, #{format_class format_name}, self; "\
"extend Card::Set::AbstractFormat"
end
end
|
67
68
69
70
71
|
# File 'lib/card/mod/loader/set_loader.rb', line 67
def format_class format_name
klass = ["Card::Format"]
klass << module_name(format_name) if format_name
klass.join "::"
end
|
#helper_module? ⇒ Boolean
73
74
75
76
77
78
79
|
# File 'lib/card/mod/loader/set_loader.rb', line 73
def helper_module?
if @is_helper_module.nil?
@is_helper_module = @content =~ /\A#!\s?not? set module/
else
@is_helper_module
end
end
|
#module_name(format_name) ⇒ Object
63
64
65
|
# File 'lib/card/mod/loader/set_loader.rb', line 63
def module_name format_name
Card::Format.format_class_name format_name
end
|
#offset ⇒ Object
correct line number for error messages
82
83
84
|
# File 'lib/card/mod/loader/set_loader.rb', line 82
def offset
-5
end
|
#processed_content ⇒ Object
49
50
51
52
|
# File 'lib/card/mod/loader/set_loader.rb', line 49
def processed_content
add_explicit_format_modules if @strategy.
super
end
|
#to_const ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/card/mod/loader/set_loader.rb', line 39
def to_const
return Object if simple_load?
@modules.inject(pattern_class) do |const, name_part|
const.const_get_or_set name_part do
Module.new
end
end
end
|