This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
feat(php-storybook): Converting the php generated story files to CSF - front-1379 #513
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ | |||||
*/ | ||||||
class storyHelpers { | ||||||
// Used to prepend a string in a file. | ||||||
function prepend($string, $orig_filename) { | ||||||
function prependToStory($string, $orig_filename) { | ||||||
$context = stream_context_create(); | ||||||
$orig_file = fopen($orig_filename, 'r', 1, $context); | ||||||
|
||||||
|
@@ -88,4 +88,64 @@ function baseComponent($variant) { | |||||
|
||||||
return $base_component; | ||||||
} | ||||||
// Creates a story.js and links the README file in the given folder. | ||||||
function createStoryFiles( | ||||||
$folder, | ||||||
$base_component, | ||||||
$adapted_variant, | ||||||
$variant, | ||||||
$deprecated_component, | ||||||
$component_group, | ||||||
$packages_folder | ||||||
) { | ||||||
// Not sure why we needed this, but it's the case. | ||||||
if (!is_dir($folder . DIRECTORY_SEPARATOR . 'story')) { | ||||||
mkdir($folder . DIRECTORY_SEPARATOR . 'story'); | ||||||
} | ||||||
// Prepare a folder for the js rendered files. | ||||||
if (!is_dir($folder . DIRECTORY_SEPARATOR . 'js')) { | ||||||
mkdir($folder . DIRECTORY_SEPARATOR . 'js'); | ||||||
} | ||||||
// Get the story template. | ||||||
$story_template = file_get_contents(__DIR__ . '/../resources/story-template.txt'); | ||||||
|
||||||
// Replace the content with our variables. | ||||||
$story_content = str_replace( | ||||||
['#component#', '#componentVariant#', '#phpFileName#', '#deprecated#', '#componentGroup#'], | ||||||
[ucfirst($base_component), $adapted_variant, $variant, $deprecated_component, $component_group] | ||||||
, $story_template | ||||||
); | ||||||
// Here we createthe story file. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
file_put_contents( | ||||||
$folder . DIRECTORY_SEPARATOR . 'story' . DIRECTORY_SEPARATOR . $base_component . '.story.js', | ||||||
$story_content, FILE_APPEND | LOCK_EX | ||||||
); | ||||||
// Symlink the docs. | ||||||
$link = $folder . DIRECTORY_SEPARATOR . 'README.md'; | ||||||
$target = $packages_folder . DIRECTORY_SEPARATOR . 'ec-component-' . $base_component . DIRECTORY_SEPARATOR . 'README.md'; | ||||||
if (!file_exists($link) && file_exists($target)) { | ||||||
symlink($target, $link); | ||||||
} | ||||||
} | ||||||
// Code to import a variant for the story file. | ||||||
function setImportCode($adapted_variant, $variant, $result_extension) { | ||||||
$import = "import " . $adapted_variant . " from '../" . $variant . $result_extension . "';\n"; | ||||||
$import .= "import " . $adapted_variant . "Js from '../js/" . $variant . ".js.html';\n"; | ||||||
return $import; | ||||||
} | ||||||
// Code to export a story. | ||||||
function setExportCode($variant_name, $adapted_variant) { | ||||||
return "export const ". $variant_name . " = () => " . $adapted_variant .";\n\n"; | ||||||
} | ||||||
// Code to define the story for a given export. | ||||||
function setStoryCode($variant_name, $adapted_variant) { | ||||||
return $variant_name . ".story = { parameters: { notes: { markdown: docs }, diff: { jsmarkup: " . $adapted_variant . "Js }}};\n\n"; | ||||||
} | ||||||
// Update the story file. | ||||||
function updateStoryFile($folder, $base_component, $data_story) { | ||||||
file_put_contents( | ||||||
$folder . DIRECTORY_SEPARATOR . 'story' . DIRECTORY_SEPARATOR . $base_component . '.story.js', | ||||||
$data_story, FILE_APPEND | LOCK_EX | ||||||
); | ||||||
} | ||||||
} |
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 |
---|---|---|
@@ -1,25 +1,11 @@ | ||
import { storiesOf } from '@storybook/html'; | ||
import { withNotes } from '@ecl-twig/storybook-addon-notes'; | ||
import withCode from '@ecl-twig/storybook-addon-code'; | ||
import { withDiff } from '@ecl-twig/storybook-addon-diff'; | ||
import { withJsCode } from '@ecl-twig/storybook-addon-jscode'; | ||
import jsCode from '../js/#phpFileName#.js.html'; | ||
|
||
import docs from '../README.md'; | ||
import #componentVariant# from '../#phpFileName#.php.html'; | ||
|
||
storiesOf('Components/#deprecated##componentGroup##component#', module) | ||
.addDecorator(withNotes) | ||
.addDecorator(withCode) | ||
.addDecorator(withJsCode) | ||
.addDecorator(withDiff) | ||
.add( | ||
'#phpFileName#', | ||
() => { | ||
return #componentVariant#; | ||
}, | ||
{ | ||
notes: { markdown: docs }, | ||
diff: { jsmarkup: jsCode } | ||
}, | ||
) | ||
export default { | ||
title: 'Components/#deprecated##componentGroup##component#', | ||
decorators: [withCode, withNotes, withJsCode, withDiff], | ||
}; | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless comment. You need this folder because the configurations expect the story file to be in this folder...