8 changed files with 88 additions and 23 deletions
@ -1,4 +1,4 @@ |
|||
# Motivation / Why React? |
|||
# Why React? |
|||
|
|||
React is a JavaScript library for creating user interfaces by Facebook and Instagram. Many people choose to think of React as the **V** in **[MVC](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller)**. |
|||
|
@ -1,4 +1,4 @@ |
|||
# Scaling Up and Using Multiple Components |
|||
# Multiple components |
|||
|
|||
So far, we've looked at how to write a single component to display data and handle user input. Next let's examine one of React's finest features: composability. |
|||
|
@ -1,4 +1,4 @@ |
|||
## Build reusable component libraries! |
|||
## Reusable components |
|||
|
|||
When designing interfaces, break down the common design elements (buttons, form fields, layout components, etc) into reusable components with well-defined interfaces. That way, the next time you need to build some UI you can write much less code, which means faster development time, less bugs, and less bytes down the wire. |
|||
|
@ -1,4 +1,4 @@ |
|||
# Working with your environment |
|||
# Tooling integration |
|||
|
|||
Every project uses a different system for building and deploying JavaScript. We've tried to make React as environment-agnostic as possible. |
|||
|
@ -0,0 +1,63 @@ |
|||
import glob |
|||
import os |
|||
|
|||
def build_header(id, title, prev, next): |
|||
prevtext = nexttext = '' |
|||
if prev: |
|||
prevtext = 'prev: ' + prev + '\n' |
|||
if next: |
|||
nexttext = 'next: ' + next + '\n' |
|||
return '''--- |
|||
id: %s |
|||
title: %s |
|||
layout: docs |
|||
%s%s---''' % (id, title, prevtext, nexttext) |
|||
|
|||
def sanitize(content): |
|||
title,content = content.split('\n', 1) |
|||
title = title[2:].strip() |
|||
return title,content.replace('# ', '## ').strip() |
|||
|
|||
def get_dest(filename): |
|||
return os.path.join(os.path.dirname(filename), '..', os.path.basename(filename)) |
|||
|
|||
def relative_html(filename): |
|||
if not filename: |
|||
return None |
|||
return os.path.splitext(os.path.basename(filename))[0] + '.html' |
|||
|
|||
def generate_nav_item(filename, title): |
|||
basename = os.path.splitext(os.path.basename(filename))[0] |
|||
return ' <li><a href="/react/docs/%s.html"{%% if page.id == \'%s\' %%} class="active"{%% endif %%}>%s</a></li>\n' % (basename, basename, title) |
|||
|
|||
def main(): |
|||
docs = [None] + glob.glob(os.path.join(os.path.dirname(os.path.abspath(__file__)), '*.md'))[:-1] + [None] |
|||
nav = ''' |
|||
<div class="nav-docs"> |
|||
<div class="nav-docs-section"> |
|||
<h3>React documentation</h3> |
|||
<ul> |
|||
%s |
|||
</ul> |
|||
</div> |
|||
</div>''' |
|||
items = '' |
|||
for i in xrange(1, len(docs) - 1): |
|||
prev = relative_html(docs[i - 1]) |
|||
next = relative_html(docs[i + 1]) |
|||
with open(docs[i], 'r') as src, open(get_dest(docs[i]), 'w') as dest: |
|||
title,content = sanitize(src.read()) |
|||
header = build_header( |
|||
os.path.splitext(os.path.basename(docs[i]))[0], |
|||
title, |
|||
prev, |
|||
next |
|||
) |
|||
dest.write(header + '\n' + content) |
|||
if docs[i].count('.') == 1: |
|||
items += generate_nav_item(docs[i], title) |
|||
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '_includes', 'nav_docs.html'), 'w') as f: |
|||
f.write(nav % items) |
|||
|
|||
if __name__ == '__main__': |
|||
main() |
Loading…
Reference in new issue