Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Load real or test post content into the same global variable
  • Loading branch information
nylen committed Mar 31, 2017
commit d032dc001290d243809f35dc11a04ec0c84b205a
18 changes: 5 additions & 13 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,11 @@ function gutenberg_scripts_and_styles( $hook ) {
wp_enqueue_script(
'wp-editor',
plugins_url( 'editor/build/index.js', __FILE__ ),
array( 'wp-blocks', 'wp-element', 'gutenberg-content' ),
array( 'wp-blocks', 'wp-element' ),
false, // $ver
true // $in_footer
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere, I've restructured the code in this function to avoid long lines, which are really detrimental to code readability. I'd recommend that we do this throughout the project, and add rule(s) to our linting setup(s) accordingly.


// Temporary test content
wp_register_script(
'gutenberg-content',
plugins_url( 'post-content.js', __FILE__ )
);

// Load an actual post if an ID is specified
$post_to_edit = null;
if ( isset( $_GET['post_id'] ) && (int) $_GET['post_id'] > 0 ) {
Expand All @@ -146,22 +140,20 @@ function gutenberg_scripts_and_styles( $hook ) {
// Initialize the post data...
if ( $post_to_edit ) {
// ...with a real post
wp_add_inline_script(
'wp-editor',
'wp.editor.post = ' . json_encode( $post_to_edit )
);
wp_localize_script( 'wp-editor', '_wpGutenbergPost', $post_to_edit );
} else {
// ...with some test content
// TODO: replace this with error handling
wp_add_inline_script(
'wp-editor',
'wp.editor.post = { content: { raw: window.content } };'
file_get_contents( plugin_dir_path( __FILE__ ) . 'post-content.js' )
);
}

// Initialize the editor
wp_add_inline_script(
'wp-editor',
'wp.editor.createEditorInstance( \'editor\', wp.editor.post );'
'wp.editor.createEditorInstance( \'editor\', _wpGutenbergPost );'
);

/**
Expand Down
59 changes: 33 additions & 26 deletions post-content.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
window.content = [
'<!-- wp:core/heading -->',
'<h1>1.0 Is The Loneliest Number</h1>',
'<!-- /wp:core/heading -->',
/**
* Temporary test post content
*/
var _wpGutenbergPost = {
content: {
raw: [
'<!-- wp:core/heading -->',
'<h1>1.0 Is The Loneliest Number</h1>',
'<!-- /wp:core/heading -->',

'<!-- wp:core/text -->',
'<p>I imagine prior to the launch of the iPod, or the iPhone, there were teams saying the same thing: the copy + paste guys are <em>so close</em> to being ready and we know Walt Mossberg is going to ding us for this so let\'s just not ship to the manufacturers in China for just a few more weeks… The Apple teams were probably embarrassed. But <strong>if you\'re not embarrassed when you ship your first version you waited too long</strong>.</p>',
'<!-- /wp:core/text -->',
'<!-- wp:core/text -->',
'<p>I imagine prior to the launch of the iPod, or the iPhone, there were teams saying the same thing: the copy + paste guys are <em>so close</em> to being ready and we know Walt Mossberg is going to ding us for this so let\'s just not ship to the manufacturers in China for just a few more weeks… The Apple teams were probably embarrassed. But <strong>if you\'re not embarrassed when you ship your first version you waited too long</strong>.</p>',
'<!-- /wp:core/text -->',

'<!-- wp:core/image -->',
'<figure><img src="https://cldup.com/Bc9YxmqFnJ.jpg" /></figure>',
'<!-- /wp:core/image -->',
'<!-- wp:core/image -->',
'<figure><img src="https://cldup.com/Bc9YxmqFnJ.jpg" /></figure>',
'<!-- /wp:core/image -->',

'<!-- wp:core/text -->',
'<p>A beautiful thing about Apple is how quickly they obsolete their own products. I imagine this also makes the discipline of getting things out there easier. Like I mentioned before, the longer it’s been since the last release the more pressure there is, but if you know that if your bit of code doesn’t make this version but there’s the +0.1 coming out in 6 weeks, then it’s not that bad. It’s like flights from San Francisco to LA, if you miss one you know there’s another one an hour later so it’s not a big deal. Amazon has done a fantastic job of this with the Kindle as well, with a new model every year.</p>',
'<!-- /wp:core/text -->',
'<!-- wp:core/text -->',
'<p>A beautiful thing about Apple is how quickly they obsolete their own products. I imagine this also makes the discipline of getting things out there easier. Like I mentioned before, the longer it’s been since the last release the more pressure there is, but if you know that if your bit of code doesn’t make this version but there’s the +0.1 coming out in 6 weeks, then it’s not that bad. It’s like flights from San Francisco to LA, if you miss one you know there’s another one an hour later so it’s not a big deal. Amazon has done a fantastic job of this with the Kindle as well, with a new model every year.</p>',
'<!-- /wp:core/text -->',

'<!-- wp:core/quote -->',
'<blockquote><p>Real artists ship.</p><footer><p><a href="http://www.folklore.org/StoryView.py?story=Real_Artists_Ship.txt">Steve Jobs, 1983</a></p></footer></blockquote>',
'<!-- /wp:core/quote -->',
'<!-- wp:core/quote -->',
'<blockquote><p>Real artists ship.</p><footer><p><a href="http://www.folklore.org/StoryView.py?story=Real_Artists_Ship.txt">Steve Jobs, 1983</a></p></footer></blockquote>',
'<!-- /wp:core/quote -->',

'<!-- wp:core/image -->',
'<figure><img src="https://cldup.com/vuGcj2VB8M.jpg" /><figcaption>Beautiful landscape</figcaption></figure>',
'<!-- /wp:core/image -->',
'<!-- wp:core/image -->',
'<figure><img src="https://cldup.com/vuGcj2VB8M.jpg" /><figcaption>Beautiful landscape</figcaption></figure>',
'<!-- /wp:core/image -->',

'<!-- wp:core/text -->',
'<p>By shipping early and often you have the unique competitive advantage of hearing from real people what they think of your work, which in best case helps you anticipate market direction, and in worst case gives you a few people rooting for you that you can email when your team pivots to a new idea. Nothing can recreate the crucible of real usage.</p>',
'<!-- /wp:core/text -->',
'<!-- wp:core/text -->',
'<p>By shipping early and often you have the unique competitive advantage of hearing from real people what they think of your work, which in best case helps you anticipate market direction, and in worst case gives you a few people rooting for you that you can email when your team pivots to a new idea. Nothing can recreate the crucible of real usage.</p>',
'<!-- /wp:core/text -->',

'<!-- wp:core/embed url:https://www.youtube.com/watch?v=Nl6U7UotA-M -->',
'<iframe width="560" height="315" src="//www.youtube.com/embed/Nl6U7UotA-M" frameborder="0" allowfullscreen></iframe>',
'<!-- /wp:core/embed -->'
].join( '' );
'<!-- wp:core/embed url:https://www.youtube.com/watch?v=Nl6U7UotA-M -->',
'<iframe width="560" height="315" src="//www.youtube.com/embed/Nl6U7UotA-M" frameborder="0" allowfullscreen></iframe>',
'<!-- /wp:core/embed -->',
].join( '' ),
},
};