Class: Twee2::StoryFormat
- Inherits:
-
Object
- Object
- Twee2::StoryFormat
- Defined in:
- lib/twee2/story_format.rb
Class Method Summary collapse
-
.known_names ⇒ Object
Returns an array containing the known StoryFormat names.
Instance Method Summary collapse
-
#compile ⇒ Object
Given a story file, injects it into the StoryFormat and returns the HTML results.
-
#initialize(name) ⇒ StoryFormat
constructor
Loads the StoryFormat with the specified name.
Constructor Details
#initialize(name) ⇒ StoryFormat
Loads the StoryFormat with the specified name
8 9 10 11 12 13 14 15 |
# File 'lib/twee2/story_format.rb', line 8 def initialize(name) raise(StoryFormatNotFoundException) if !File::exists?(format_file_path = Twee2::buildpath("storyFormats/#{name}/format.js")) @name = name format_file = File::read(format_file_path) format_data = format_file.match(/(["'])source\1 *: *(["']).*?[^\\]\2/)[0] format_data_for_json = "\{#{format_data}\}" @source = JSON.parse(format_data_for_json)['source'] end |
Class Method Details
Instance Method Details
#compile ⇒ Object
Given a story file, injects it into the StoryFormat and returns the HTML results
18 19 20 |
# File 'lib/twee2/story_format.rb', line 18 def compile @source.gsub('{{STORY_NAME}}', Twee2::build_config.story_name).gsub('{{STORY_DATA}}', Twee2::build_config.story_file.xmldata).gsub('{{STORY_FORMAT}}', @name) end |