Giter Club home page Giter Club logo

b3's Introduction

B3

B3 is a Backbone.js starter theme for WordPress.

It is designed as a launchpad for your own cutting edge themes: so clone it, rename it, hack it and republish it.

Warning

B3 is compatible with v1 of the WP API only. We're waiting for development on the v2 branch to stabilise before making further changes to this project.

We recommend that you either use the version on WordPress.org or at the very least stick to the master branch to minimize issues.

Also, please bear in mind that B3 is a work in progress and as such we can't (yet) recommend it for production use. Do so at your own risk.

Getting Started

This brief guide assumes you have at least some familiarity with WordPress and JavaScript development. We fully intend to make this process as painless as possible, but we still have a few critical features taking precedence.

  1. Install and activate the WP API plugin.

  2. Make sure pretty permalinks are enabled on your WordPress install. They are required for the REST API to work.

  3. Clone the B3 REST API Extensions repository into your plugins folder and activate the plugin:

    $ cd your/wordpress/install/wp-content/plugins
    $ git clone https://github.com/B3ST/B3-REST-API.git b3-rest-api
    
  4. Clone this repository into your themes folder:

    $ cd your/wordpress/install/wp-content/themes
    $ git clone https://github.com/B3ST/B3.git b3
    
  5. We're not done yet, we still need to install required Node dependencies (the theme is built automatically at the end):

    $ cd b3
    $ gem install scss-lint
    $ npm install -g gulp bower requirejs
    $ npm install
    
  6. Activate the theme. You're ready to start hacking!

Build Automation

B3 comes with a few Gulp tasks to automate building and testing:

  • gulp build: Builds the theme application.
  • gulp watch: Watches your codebase for changes, triggering a partial rebuild and refreshing the browser.
  • gulp jasmine: Runs automated Jasmine tests in the browser, with support for live updates.
  • gulp phpunit: Runs automated PHPUnit tests in the terminal.

Extra Tasks

You'll need these less often, since most of them are subtasks called by the ones above:

  • gulp bower: Installs Bower dependencies. This runs on build.
  • gulp build:fonts: Deploys font assets to the public application folder.
  • gulp build:images: Compresses image assets and deploys them to the public application folder.
  • gulp build:scripts: Compiles, minifies and deploys JavaScript sources.
  • gulp build:styles: Compiles, lints, minifies and deploys Sass styles as CSS.
  • gulp build:templates: Compiles and deploys Dust.js templates.
  • gulp clean: Removes all compiled files, leaving only the original sources.
  • gulp jshint: Lints JavaScript sources.
  • gulp rebuild: Builds the theme application from scratch.

Build Configuration

Gulp task parameters (such as file paths and BrowserSync configurations) are provided in a centralized file located at gulp/config.js.

Optimization

By default, the provided Gulp tasks will minify scripts but not concatenate them, leading to dozens of file requests to the server.

To avoid this, you can bundle theme modules for deployment using the RequireJS Optimizer.

The easiest and fastest way to do this is by using the r.js command line utility. If you completed the installation steps at the start of this guide, you should already have it. To package the site for deployment, open a terminal at the theme's root folder and enter:

$ r.js -o build.js

This will convert most scripts in your theme's dist folder into concatenated versions.

Most scripts will go into main.js, the same file your un-optimized theme would load on launch. Files that for any reason were not concatenated into main.js will remain in their original places, ensuring the theme is still able to find them.

r.js will combine external libraries as infrastructure.js. This file will probably be larger than your theme, but also less likely to change over time, and so it makes sense to keep it separate to make the most of browser and CDN caches.

Licensing

We release B3 under an MIT license. This is to make sure you don't run into licensing issues should you decide to repackage portions of the project as a Phonegap/Cordova application.

b3's People

Contributors

goblindegook avatar pcruz7 avatar s3rgiosan avatar xipasduarte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

b3's Issues

Add router support for tokens in the $param<regex> format

In order to resolve persistent conflicts with date-based permalinks, we should implement support for parts in the $param<regex> format.

This will allow us to replace :year with $year<\d+> in the route definitions sent by the B3 REST API, and prevent the router from mistakenly sending post and page requests to a date archive.

We're following Play! Framework's example, so for more (but not much more): https://www.playframework.com/documentation/2.1.1/ScalaRouting#Dynamic-parts-with-custom-regular-expressions

(Although they serve different purposes, implementing this will make route patterns 100% consistent with the ones used for setting up custom API endpoints in the B3-REST-API project.)

Switch CSS preprocessor from LESS to Sass

Everyone on the team is using Sass now, and even Bootstrap 4 will have it as their default. (We don't have to wait, there's a Sass-based Bootstrap 3 we can use at twbs/bootstrap-sass).

Since the CSS provided by B3 is minimal, porting the stylesheets to SCSS should be trivial.

Dequeue plugin scripts and include them via require

Third party plugins will often enqueue scripts on the frontend that interfere with B3's loading process.

These scripts must be saved to a JavaScript array and dequeued with dequeue_script(). On the JavaScript side, the application should require them.

Navigation behavior options

Here's a wild idea: make it possible for each view to configure a transition animation when navigating to another view using the Navigation behavior. A transition function or setting may be passed via the options object/callback to the Behavior.

Consider this a really low priority request, we have bigger fish to fry at the moment.

Combine navigation behaviors

Navigation behaviors should be combined into a single navigation behavior that looks at the URL and decides the best course of action. I've whittled them down to four (NavigationArchive, NavigationHome, NavigationPost, NavigationURL), but they use different approaches: some take slug and IDs from the anchor element, others parse the URL.

We should either stop relying on ID and slug attributes (href should be enough) or embrace them and create a consistent interface for them.

That way we can fully reuse the Navigation behavior, which should handle linking around the application. For example, rather than handle its own links, the MenuItem behavior should declare support for the Navigation behavior. Post content, widgets and archives should all support the same Navigation behavior as well.

Deep linking does not update menu item highlights

Navigating straight to a deep link does not update the menu appearance.

For example, pointing your browser to http://b3.dev/category/images does not highlight the menu items in the Category > Images path.

The onMenuItemUpdate event handler in the new MenuItemActivation behavior should also look at the menu item's object (containing the post or term ID), object_parent and object_type to determine whether the menu should be highlighted when the application loads.

Bower install needs to build Sinon

A pre-built Sinon isn't fetched by Bower, we will need to build it ourselves.

In the meantime, do the following as a workaround, starting at the B3 project root:

$ cd bower_components/sinon
$ gem install juicer
$ npm install formatio
$ ./build
$ cd ../..
$ gulp bower

Implement a theme fallback strategy

What happens when Google tries to crawl a site that uses a B3-based theme? What if a user's browser doesn't support JavaScript?

The theme should be able to detect these situations and serve the user/crawler a server-rendered version of the page. This can be done by:

Rendering the B3 application using Phantom.js

  • Pro: Visual fidelity.
  • Con: Requires Node.js on the server. While it's the best possible solution, this requirement alone makes me not want to go this route, since it severely hampers compatibility, ease of use and, ultimately, adoption.
  • Con: Anything not available on page load (as a result of further on-page interaction, timed events, etc.) may not be displayed.

Serving the content using a secondary theme

  • Pro: No extra dependencies, WordPress handles theme switching.
  • Pro: Fallback is possible using the theme's own PHP resources, it's not necessary to install a second theme for this.
  • Con: Unless the secondary theme is custom-built to look the same (read: extra work), the page will not match the B3 application's visual style.

Keeping a single theme, but reusing some components

  • Pro: We may be able to reuse WP API models.
  • Pro: We may be able to render the same Dust templates on the client and the server.
  • Con: Everything in between (views, custom helpers, controllers, etc.) has to be duplicated, in PHP and JavaScript.

Search results collection updates but isn't displayed once the search view is replaced

How to reproduce (I'm using the wptest.io dataset for this):

  1. Search for "super"
  2. Results appear
  3. Instead of clicking on a result, pick a post category
  4. Now go back to the search box and add "califragilisticexpialidocious"

The request is made and the collection is updated, but the view is still showing the previously selected category.

Resetting the search (which triggers a view teardown event) resolves the problem.

So . . . always tear the view down on a search lookup?

Use the Pagination behavior properly

It's not the PaginationView that should have a Pagination behavior.

Rather, it's the ArchiveView and PostView that should mixin that behavior.

Support WordPress Heartbeat

Let's have some live updates going!

What's needed:

  1. Enqueue the WordPress heartbeat script.
  2. Listen to the heartbeat-send and heartbeat-tick events.
  3. Profit!

heartbeat-tick

This event is triggered approximately every 15 seconds (the default).

$(document).on( 'heartbeat-tick', function(e, data) {
  // Update your models and collections and views and gewgaws here!
  console.log( data );
});

heartbeat-tick supports "namespaces" as heartbeat-tick.{handle}, which is the recommended approach if we know what we're looking for. There will be a heartbeat-tick.b3 specifically for our stuff.

Taking the heartbeat's pulse will allow us to take action and update content on the fronted whenever changes occur server-side.

Enqueuing data and heartbeat-send

We probably won't need this now that we have a fancy REST API, but the WordPress Heartbeat provides a method to allow us to send data back to the server. (Although I can see this could be useful if we ever need to implement a way to enable/disable certain notifications.)

wp.heartbeat.enqueue(handle, payload, override);

Mind the "enqueue" thing: the payload isn't sent immediately, it's enqueued and sent only on the following tick. You can check if your data was sent using wp.heartbeat.isQueued(handle), which returns the data. If you need to change or replace the payload, you can re-enqueue the object using the same handle and the override flag set to true.

Theres a wp.heartbeat.dequeue(handle) method as well.

When this data is finally sent, a heartbeat-send event is triggered:

$(document).on('heartbeat-send', function(e, data) {
  // If you change data here, it will also be sent back to the server
  console.log( data );
});

The server receives this data via POST and is able to make changes to send back to the browser through the heartbeat_received and heartbeat_nopriv_received filters. (The nopriv option is for guest users.) The browser will then receive all the data on the next heartbeat-tick.

Search result links don't work if searching from a post page

How to reproduce:

  1. Go to any post page (e.g. "Hello world!").
  2. Start searching.
  3. The links in the results list do not work.

However:

  1. Go to any archive (main index, category, etc.)
  2. Start searching.
  3. The links in the results list are working.

Post views don't have the same click events/behaviors as archive views. Aren't search results always put into an archive view?

View loading as a behavior

Methinks the view loading class is a prime candidate to be turned into a behavior.

Easy to switch on or off the behavior, configure its options from the view, or even subclass if you need deeper changes.

Since behaviors already listen to the view's events, it should be pretty easy to know when each view is waiting to load, etc.

ReplyableView should be a behavior

So any post that supports replies should declare support for the Reply behavior instead.

Individual comments support the Reply behavior too.

I'm kicking myself that I didn't look at Behaviors sooner!

Archive Headers

  • Author header
  • Date header
  • Header should include data from the taxonomy or author being displayed (title label, description, etc.)

See:

  • GET /wp-json/taxonomies/category (name, labels.singular_name)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.