Git Product home page Git Product logo

polymer-theme's Introduction

Polymer SPA Theme for Wordpress

This theme aims to be a starting point to develop a Polymer SPA applications using Wordpress to feed it. It's based on the Polymer's team Polymer starting Kit.

It is still in development stage and some bugs may appear.

Installation

Basic installation

  • Clone this repository in your server; git clone https://github.com/trofrigo/polymer-theme.git
  • Install the theme's bower dependencies. Execute bower install in the root of this project. In order to this, Bower must be installed.
  • Install and activate this theme into your Wordpress installation.
  • Create a page called Blog. This is needed in order to be able to edit the blog's title and description.

NOTE: After the first installation, you may need go to the Polymer theme admin's application into the Wordpress backoffice and save this configuration for a very first time.

If you are using a Wordpress installation previous to the 4.7.3 version, you have to install the WP REST API plugin as well.

Advanced installation

In order to improve the user final experience and daily blog's workflow, some plugins and third party software may be installed.

Varnish caches all the API requests, improving the speed transition between pages.

WP EDITOR let you edit and create files and directories inside yours Wordpress backoffice. This allows you to create edit custom element's files.

File structure

The whole Polymer's application can be found into the src/ folder. There you will find three folders admin/, core/ and templates/.

The admin/ folder contains all the admin's application that allows you to edit the themes's configuration.

All the templates must be placed into the templates/ folder. This templates ships with some of them:

  • template-blog.html
  • template-blog-detail.html
  • template-page-detail.html

Theme's core is placed into the core/ folder. There you will find some elements used by this theme, that you can reuse in your own templates or elements.

Admin and configuration

Once this theme is installed, you will find inside your Wordpress backoffice a new option, polymer-theme:

Backoffice admin options

Inside this new page you will find 3 tabs:

Admin element

General Settings

This first tab manages some general settings, as for example:

  • SPA icons. Allows you to define several icons sizes.
  • Theme color. That's the color used for some browser to color its navbar.
  • Google Tag Manager. By default, this theme ships with Google Tag Manager ready to use.

Templates

Every time that this theme try to resolve a url, uses some to rules to infer a proper template. Those general rules can be overwritten to any page or post in your site.

Admin templates

Every time that a post or page is created, or every time that a new template is added into the src/templates/ folder, it will appear as an option inside the select elements.

State

This theme uses the Google's UniFlow element to work with the inner state of the application. There are two kind of values inside the application state, those required by the application itself and those required by the user.

Every element that implements the UniFlow.StateAware, will be notified every time that the state changes.

If the user needs to set a value, it can be add in this section. Those values will be available inside the custom attribute of the application's state.

<dom-module id="my-element">
    <template>
        <style></style>

        <h1>state.custom.myValue</h1>

    </template>
    Polymer({
          is: 'my-element',

          behaviors: [
            UniFlow.StateAware
          ]
    });
</dom-module>

Custom elements

Templates

Understanding the templates system

Every time the route changes, the shell tries to infer the most appropriate template. To do this, the shell fetch the information that Wordpress has for this url using the polymer-theme-route. This information is eventually passed to the template, that is the info that is typically into the Wordpress's Loop.

Once the template is selected, the shell call to an init(item) method that the template must implement. That method receives a param with the Loop's info. At this point, the shell waits to the template to fire a method called ready, that notifies that template is ready to be shown.

In a simple example, a template receives the Loop info, bind it, and notifies that is ready to go.

Polymer({
    is: 'post-detail',
    init: function (item) {
        this.set('item', item);
        this.fire('ready');
    }
});

In a more complex example, a template that renders a page, may need to find all page's children. In this case the template needs to fetch this children information in order to be ready.

Polymer({
    is: 'page-children',
    init: function (item) {
        this.wp.pages().param('parent', item.id)
            .then(function (response) {
                this.set('children', response);
                this.fire('ready');
            }.bind(this));
    }
});

NOTE: in this last example, the templates uses the polymer-theme-wp-api to fetch this information.

Template hierarchy

This theme tries to mimic the Wordpress template behaviour. Every time the route changes, theme's router will find what the taxonomy and the slug of the next view is. Once those params are determined, the shell will try to find a template for the view.

First of all, will look for custom rule for this slug, if this rule does not exist, will resolve into templates/template-{taxonomy}-detail.html.

This hierarchy allows the user to set a default view for a taxonomy detail (typically post-detail and page-detail) and also overwrite it for any special post just creating a new rule.

Changelog

v0.1.0

  • First theme's version

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

Copyright (c) 2017 Rodrigo Sancho

Licensed under the MIT license.

polymer-theme's People

Contributors

rodrigosancho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

zahedbri

polymer-theme's Issues

Question: Best workflow for adding wordpress plugins to polymer-theme?

I apologize if this sounds like a pretty novice question... (It's been a long time since I've worked w/ wordpress directly. Fusing Polymer and Wordpress together brings up the question on the best way to fuse custom elements w/ wordpress plugins.


Adding in a plugin from the Wordpress.org Directory
or...
Adding in a custom element from the Webcomponents.org Directory


How would you go about using a Wordpress plugin inside a custom element?

For example, if I wanted to add the MailChimp Wordpress Plugin, is there a default place that these plugins would show up in your theme?

ENHANCEMENT: Add BrowserSync/ Live Reload for development

An excellent npm module I've been using within the Polymer CLI is the
generator-polymer-init-element-scaffold

It uses Yeoman to scaffold out either a bower element or internal element and adds BrowserSync along with a few other great additions. It would be awesome for some of these features to be included in your wordpress polymer-theme as well.


Repo: https://github.com/photoshelter/generator-polymer-init-element-scaffold
Installation: npm install -g generator-polymer-init-element-scaffold

image

Installation Problem

I've followed your steps and I've almost got this working... But none of the data is showing.
Can you identify my problem from the screenshots below?


I've activated the new WP Rest API plugin:

image

Changed the permalink:

image

And created the Blog page:

image

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.