-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change transforming file content into metadata and slides to improve …
…reusability
- Loading branch information
1 parent
96e900f
commit ae3ee4f
Showing
7 changed files
with
564 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# frozen_string_literal: true | ||
|
||
module Slideck | ||
# Responsible for wrapping parsed global and slide metadata | ||
# | ||
# @api private | ||
class MetadataWrapper | ||
# Create a MetadataWrapper instance | ||
# | ||
# @example | ||
# MetadataWrapper.new(metadata, metadata_converter, metadata_defaults) | ||
# | ||
# @param [Slideck::Metadata] metadata | ||
# the metadata | ||
# @param [Slideck::MetadataConverter] metadata_converter | ||
# the metadata converter | ||
# @param [Slideck::MetadataDefaults] metadata_defaults | ||
# the metadata defaults | ||
# | ||
# @api public | ||
def initialize(metadata, metadata_converter, metadata_defaults) | ||
@metadata = metadata | ||
@metadata_converter = metadata_converter | ||
@metadata_defaults = metadata_defaults | ||
end | ||
|
||
# Wrap parsed global and slide metadata | ||
# | ||
# @example | ||
# metadata_wrapper.wrap({metadata: {}, slides: []}) | ||
# | ||
# @param [Hash{Symbol => Hash, String}] deck | ||
# the deck of parsed metadata and slides | ||
# | ||
# @return [Array<Slideck::Metadata, Hash>] | ||
# | ||
# @api public | ||
def wrap(deck) | ||
[ | ||
build_metadata(deck[:metadata], @metadata_defaults), | ||
deck[:slides].map do |slide| | ||
{ | ||
content: slide[:content], | ||
metadata: build_metadata(slide[:metadata], {}) | ||
} | ||
end | ||
] | ||
end | ||
|
||
private | ||
|
||
# Build metadata | ||
# | ||
# @param [Hash{Symbol => Object}] custom_metadata | ||
# the custom metadata | ||
# @param [#merge] defaults | ||
# the defaults to merge with | ||
# | ||
# @return [Slideck::Metadata] | ||
# | ||
# @api private | ||
def build_metadata(custom_metadata, defaults) | ||
@metadata.from(@metadata_converter, custom_metadata, defaults) | ||
end | ||
end # MetadataWrapper | ||
end # Slideck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
module Slideck | ||
# Responsible for transforming parsed data into metadata and slides | ||
# | ||
# @api private | ||
class Transformer | ||
# Create a Transformer instance | ||
# | ||
# @example | ||
# Transformer.new(loader, parser, metadata_wrapper) | ||
# | ||
# @param [Slideck::Loader] loader | ||
# the loader | ||
# @param [Slideck::Parser] parser | ||
# the parser | ||
# @param [Slideck::MetadataWrapper] metadata_wrapper | ||
# the metadata wrapper | ||
# | ||
# @api public | ||
def initialize(loader, parser, metadata_wrapper) | ||
@loader = loader | ||
@parser = parser | ||
@metadata_wrapper = metadata_wrapper | ||
end | ||
|
||
# Read slides from a file | ||
# | ||
# @example | ||
# transformer.read("slides.md") | ||
# | ||
# @param [String] filename | ||
# the filename to read slides from | ||
# | ||
# @return [Array<Slideck::Metadata, Array<Hash>>] | ||
# | ||
# @api public | ||
def read(filename) | ||
@metadata_wrapper.wrap(@parser.parse(@loader.load(filename))) | ||
end | ||
end # Transformer | ||
end # Slideck |
Oops, something went wrong.