-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
PostNodeBuilder
, remove post-builder, Markup.create
- Loading branch information
Showing
19 changed files
with
409 additions
and
398 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
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
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,70 @@ | ||
import Post from '../models/post'; | ||
import MarkupSection from '../models/markup-section'; | ||
import ImageSection from '../models/image'; | ||
import Marker from '../models/marker'; | ||
import Markup from '../models/markup'; | ||
import Card from '../models/card'; | ||
import { normalizeTagName } from '../utils/dom-utils'; | ||
|
||
export default class PostNodeBuilder { | ||
constructor() { | ||
this.markupCache = {}; | ||
} | ||
|
||
createPost() { | ||
const post = new Post(); | ||
post.builder = this; | ||
return post; | ||
} | ||
|
||
createMarkupSection(tagName, markers=[], isGenerated=false) { | ||
tagName = normalizeTagName(tagName); | ||
const section = new MarkupSection(tagName, markers); | ||
if (isGenerated) { | ||
section.isGenerated = true; | ||
} | ||
return section; | ||
} | ||
|
||
createImageSection(url) { | ||
let section = new ImageSection(); | ||
if (url) { | ||
section.src = url; | ||
} | ||
return section; | ||
} | ||
|
||
createCardSection(name, payload={}) { | ||
return new Card(name, payload); | ||
} | ||
|
||
createMarker(value, markups=[]) { | ||
const marker = new Marker(value, markups); | ||
marker.builder = this; | ||
return marker; | ||
} | ||
|
||
createBlankMarker() { | ||
return new Marker('__BLANK__'); | ||
} | ||
|
||
createMarkup(tagName, attributes) { | ||
tagName = normalizeTagName(tagName); | ||
|
||
let markup; | ||
|
||
if (attributes) { | ||
// FIXME: This could also be cached | ||
markup = new Markup(tagName, attributes); | ||
} else { | ||
if (this.markupCache[tagName]) { | ||
markup = this.markupCache[tagName]; | ||
} else { | ||
markup = new Markup(tagName, attributes); | ||
} | ||
} | ||
|
||
markup.builder = this; | ||
return markup; | ||
} | ||
} |
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
Oops, something went wrong.