Module: StoryTeller::Library::Directives

Defined in:
lib/story_teller/library/directives.rb

Overview

The StoryTeller::Library::Directives module

Constant Summary collapse

InclusionGrammarGuessTemplate =
'%<inclusion>s.h.inf.rb'.freeze
InclusionGuessesTemplate =
'%<inclusion>s.h'.freeze
PropertyModifiers =
%i[additive].freeze

Class Method Summary collapse

Class Method Details

.Attribute(attribute) ⇒ Object



57
58
59
# File 'lib/story_teller/library/directives.rb', line 57

def Attribute(attribute)
  StoryTeller::Library.declarations.add_attribute(attribute)
end

.Constant(constant, value, target = ::Object) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/story_teller/library/directives.rb', line 73

def Constant(constant, value, target = ::Object)
  return if constant.nil?
  silence_warnings do
    target.instance_eval { const_set(constant.to_sym, value) }
  end
rescue StandardError => e
  log.error "Unexpected error resetting constant #{constant}", e
  nil
end

.Default(property, value) ⇒ Object



69
70
71
# File 'lib/story_teller/library/directives.rb', line 69

def Default(property, value)
  Constant(property, value)
end

.import_global(symbol) ⇒ Object



83
84
85
# File 'lib/story_teller/library/directives.rb', line 83

def import_global(symbol)
  StoryTeller::Library.declarations.add_global(symbol)
end

.Include(inclusion) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/story_teller/library/directives.rb', line 41

def Include(inclusion)
  # warn "StoryTeller::Engine.Include(#{inclusion}) from #{caller_locations(1, 5).map { |l|
  #   "#{l.path}:#{l.lineno}"
  # }.join(' | ')}"
  inclusion = StoryTeller::Engine.language_name if /^language__$/.match(inclusion)
  grammar_guess = format(InclusionGrammarGuessTemplate, inclusion: inclusion)
  guess = File.expand_path(
    File.join(
      StoryTeller::Library.inform_gem_lib_path,
      StoryTeller::Engine.inform_code_prefix,
      grammar_guess))
  return StoryTeller::Library::Loader.load_grammar_by_path(guess) if File.exist?(guess)
  StoryTeller::Library::Loader.require_first_existing(
    format(InclusionGuessesTemplate, inclusion: inclusion).split)
end


34
35
36
37
38
39
# File 'lib/story_teller/library/directives.rb', line 34

def Link(link)
  # TODO: Implement
  # Not a high priority, because in the original Inform6 links were
  # effectively just pointers to objects loaded in memory, and so
  # were ephemeral in nature.
end

.Property(*args) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/story_teller/library/directives.rb', line 61

def Property(*args)
  if PropertyModifiers.include?(modifier_or_property = args.shift)
    StoryTeller::Library.declarations.add_property(args.shift, args.shift)
  else
    StoryTeller::Library.declarations.add_property(modifier_or_property, args.shift)
  end
end