Code Monkey home page Code Monkey logo

costingresourcewpp's Introduction

Costing Resource Calculators Plugin

Run the unit tests

First, download PHPUnit and create the autoloader file (assuming composer is already installed):

$ composer install

Then, run the unit tests:

$ ./vendor/bin/phpunit
PHPUnit 3.7.26 by Sebastian Bergmann.

Configuration read from /Users/coreymcmahon/Sites/CostingResource/phpunit.xml

.....................................................

Time: 248 ms, Memory: 6.00Mb

OK (53 tests, 184 assertions)

Install the plugin

To install the plugin, save the folder contents to the following path under your Wordpress installation:

(wordpress folder)/wp-content/plugins/CostingResource

Note: the following files and folders should be omitted when performing the upload: .git/, tests/, vendor/, .gitignore, README.md, composer.lock, composer.json, phpunit.xml. These files are only required during development

You should then navigate to the Plugins menu in the Wordpress administration dashboard, and click Activate next to the cutting calculator in the list.

Using the plugin

Once the plugin is activated, you can use it on a page or post by using the shortcode:

[costing_resource_calculators]

Make sure the template has enough horizontal space to accommodate the calculator.

Project layout

/             : Root level of the project.
front.php     : The "front controller". All requests for the plugin are passed 
                through here.
index.php     : The Wordpress Plugin metadata file. Creates the shortcode.
bootstrap.php : The bootstrap file. Responsible for including all dependencies.
assets/       : The HTML, JavaScript, images and CSS for generating the user 
                interface for the calculators.
data/         : CSV files that are used for providing the backend data for the 
                calculations.
src/          : The source-code for the calculators and HTTP routing code to 
                service AJAX requests.

Adding a New Calculator

There are a number of steps that need to be completed in order to create a new calculator.

Implement the backend calculator

Create a new folder (and PHP namespace) in src/CostingResource/ and name it after your new calculator (eg: for ExampleCalculator, use the folder / namespace Example). You'll then need to create two files in here:

  • Calculator.php: implements the calculation process. See src/SpotWelding/Calculator.php and src/Cutting/Calculator.php and follow the format used there.
  • CsvData.php: implements the data retrieval process. See src/SpotWelding/CsvData.php and src/Cutting/CsvData.php and follow the format used there.

Update the bootstrap.php file

Any PHP files that you create need to be added to bootstrap.php, otherwise they won't be loaded at runtime.

Add the Calculator to the Settings

Open the file src/CostingResource/Settings.php and add the name and namespace for the new calculator to the list of static variables. Make sure you also add the new calculator to the function getCalculatorInstanceFor(...) so that an instance of the new calculator class is returned.

Implement the HTML and JavaScript for the Calculator

Create the templates in a new folder in assets/templates/[calculator-name] as demonstrated in assets/templates/cutting and assets/templates/spot_welding. Typically you'll create index.html.php which is resposible for rendering the outer elements of the tabs, and then three sub-templates that correspond with each of the tabs.

Calculator specific JavaScript should go in assets/js/calculators/[calculator-name].js (this will be automatically included by the plugin), while any event handlers that need to be attached should be done via inline JavaScript in the respective template files. This is so the event handlers are reattached when the form is re-rendered.

Other notes

Styles go in assets/css/styles.css (no calculator specific stylesheet, just use calculator-specific ID and class attributes). Images can be placed in assets/images.

costingresourcewpp's People

Contributors

coreymcmahon avatar

Watchers

 avatar  avatar

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.