Code Monkey home page Code Monkey logo

twine-loader's Introduction

Twine-Loader

Provides a rudimentary external asset loader for Twine. Borne of my intitial frustrations with seeing how JS / CSS had to be managed as Passages, I decided to create a little macro to alleviate some of the boilerplate and allow better segmentation of assets from content.

How it works

So simple.

  • To load a CSS file, simply add: <<load css stylesheet.css>>

  • To load a JS file, do: <<load script main.js>>

Directories

By default, files will be loaded relative to the HTML file that you are using. It is possible to set default paths for root, scripts and styles:

<<load set root lib>>
<<load set styles /css/>>
<<load set scripts /js/>>

Using it

To use the loader, you will need to create a Twine passage to register this macro. Simply create a new passage, give it a script tag, and copy the contents of src/loader.min.js into it.

Once that is done, you can now load all required stylesheets, scripts from a single passage in a highly readable fashion:

<<silently>>
  <<load set root lib >>
  <<load set styles /css/ >>
  <<load set scripts /js/ >>
  
  <<load css styles.css>>
  
  <<load script util.js>>
  <<load script main.js>>
<<endsilently>>

This will have the result of loading:

  • lib/css/styles.css
  • lib/js/util.js
  • lib/js/main.js

Typically you will want to put this at in your Start passage, but it will work in any location (this could allow you to do dynamic loading of styles, for instance).

Comments, forks and pull-requests welcome :)

To-do

Provide support for loading in Macros.

twine-loader's People

Contributors

peterhughesdev avatar

Stargazers

 avatar  avatar

Watchers

 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.