Estatic

Estatic (E-commerce Static) is a static e-commerce site generator. This gem dynamically adds products from csv files to your (erb, slim, haml) templates and generates static html pages. The current templates supported are for the home_page, product_listings_page, and product_page.

Installation

$ gem install estatic

Setup

Go to your working directory

$ cd /path/to/working/directory

The working directory must have a blueprints folder which may contain the following:

  • csv folder for category/subcategory products
  • shared folder for template partials
  • css folder
  • scripts folder
  • config.yml
  • home_page.(erb,slim,haml)
  • product_listings_page.(erb,slim,haml) for your category/subcategory product listings
  • product_page.(erb,slim,haml) for individual product page
  • additional folder/s. this will be copied to your static site

files and folders are all optional depending on the requirements of your estatic site


A sample working directory structure

+-- working_directory
    +-- blueprints
        +-- csv
        |   +-- featured.csv
        |   +-- category_sample.csv
        |   +-- subcat_1.csv
        |   +-- subcat_2.csv
        +-- shared
        |   +-- partial.erb
        +-- css
        |   +-- app.css
        +-- scripts
        |   +-- app.js
        +-- optional-folder-of-other-stuff-goes-here
        |   +-- other-stuff.png
        +-- optional-folder-of-another-stuff-goes-here
        |   +-- another-stuff.ttf
        +-- config.yml
        +-- home_page.erb
        +-- product_listings_page.erb
        +-- product_page.erb

Configuration

In your config.yml

featured: featured             # translate featured.csv as home_page products
categories:
  - category_sample            # translate category_sample.csv as category products
  - category_with_subcategory: # translate subcat_1.csv and subcat_2.csv as category products
    - subcat_1                 # translate subcat_1.csv as subcategory products
    - subcat_2                 # translate subcat_2.csv as subcategory products
chunk: 20                      # maximum number of products per product_listings_page
include_product_page: true     # flag to generate product_page, default is false

category and subcategory products are rendered in product_listings_page

Manage Templates

There are instance variables you can use depending on which template:


home_page.erb, product_listings_page.erb

  • @resource - category/subcategory
    • .name
    • .products - array of products (all)
    • .subcategories - array of subcategory resource objects. only applicable if @resource is a category
  • @products - array of products per chunk (current chunk per page). for product_listings_page only.
    • an element of @products array has an .attribute_name depending on the csv header
  • @current_page
  • @total_pages

product_page.erb

  • @resource - category/subcategory
    • same as above
  • @product
    • .attribute_name - depends on the csv header

Usage

Inside your working directory

$ estatic

It will then generate an estatic_site folder

$ cd estatic_site

You can now open your generated static pages on your browser

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests or you can run guard bundle exec guard. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Fork the repo.

Bug reports and pull requests are welcome on GitHub at https://github.com/karloescota/estatic.

License

The gem is available as open source under the terms of the MIT License.

(c) Karlo Escota