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.
28
29
30
31
|
# File 'lib/card/mod/loader/set_loader.rb', line 28
def initialize modules, content_path, strategy
super
@modules.pop if helper_module?
end
|
Instance Method Details
48
49
50
51
52
53
54
55
|
# File 'lib/card/mod/loader/set_loader.rb', line 48
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
|
61
62
63
64
65
|
# File 'lib/card/mod/loader/set_loader.rb', line 61
def format_class format_name
klass = ["Card::Format"]
klass << module_name(format_name) if format_name
klass.join "::"
end
|
#helper_module? ⇒ Boolean
67
68
69
70
71
72
73
|
# File 'lib/card/mod/loader/set_loader.rb', line 67
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
57
58
59
|
# File 'lib/card/mod/loader/set_loader.rb', line 57
def module_name format_name
Card::Format.format_class_name format_name
end
|
#offset ⇒ Object
correct line number for error messages
76
77
78
|
# File 'lib/card/mod/loader/set_loader.rb', line 76
def offset
-5
end
|
#processed_content ⇒ Object
43
44
45
46
|
# File 'lib/card/mod/loader/set_loader.rb', line 43
def processed_content
add_explicit_format_modules if @strategy.
super
end
|
#to_const ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/card/mod/loader/set_loader.rb', line 33
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
|