-
Notifications
You must be signed in to change notification settings - Fork 15
Sample Pages & How to Create Them
Brendan Huffman edited this page Nov 18, 2020
·
3 revisions
rails g sample "New Page" --category desired_category
- Run the above command where
"New Page"
is the name of your new page anddesired_category
is the name of an existing sample page category or an entirely new one you'd like to create. - There are string parsing safeguards in place under the hood but in general try to name your page with spaces and capitals and your category with snake_case (see command line example above).
- Make sure you run this command in the interior
playbook
folder not the root directory of the repo (i.e. app level).
- The generator will create two index files,
index.jsx
andindex.html.erb
, in a new folder atplaybook/app/views/samples/#{your_page_name}
. You will build your sample pages inside these two files. - It will also add your new page to a category inside
samples.yml
(categories =full_page_sample:
, pages =- analytics_dashboard
) - Finally the generator will add imports and WebpackerReact config in
samples.js
. It will only append them to the file, take some time to rearrange the import alongside the others further up the page.
- You can view your sample page indexes at
localhost:8089/samples/#{your_page_name}
where#{your_page_name}
is equal to theviews/samples
folder the generator created (as described in step 1 of the last section). - You can also navigate to this page by going to the sample index at
localhost:8089/samples, finding your page under its corresponding category, and clicking the link. The index page renders dynamically based upon the [
samples.yml`](https://github.com/powerhome/playbook/blob/master/playbook/app/pb_kits/playbook/data/samples.yml) structure. It's good to check that the link(s) are functioning and the category/page is rendering as expected after adding a new page/category since it's all happening dynamically.
- If you've created a new category you'll notice the SVG preview thumbnail is coming up blank on the sample index page. You'll need to add an
svg
to theapp/assets/images
folder. The naming convention is the snake case style category name found in thesamples.yml
. See thefull_page_samples.svg
for an example.