Giter VIP home page Giter VIP logo

rint.template.based's Introduction

Rint.template.based

Under Development.

project composition

command

$ rint_create template.html variables.json output.js

configuration file

configuration file is json file that include the information about variables. the variables must be wraped with double underscore(__).

{
    "__rint_variables__": "test_string",
    "__rint_other_variables__": ["test_a", "test_b", "test_c"]
}

Template File

rint-property about basic

data-rint="variables"

data-rint="variables" allows to declare variables. It must be set on the top of the document. The variables name must be wrap with double underscore(__).

<script>
    __rint_project_name__:string
    __rint_collections__:array
</script>

data-rint="code"

data-rint="code" allows to create the code with template.

template file

<!DOCTYPE rint>
<script data-rint="variables">
    __rint_project_name__:string
    __rint_collections__:array
</script>
<script data-rint="code">
   var db = require('mongojs').connect('__rint_project_name__', __rint_collections__)
</script>

configuration file

{
    "__rint_project_name__": "basic",
    "__rint_collections__": ["users", "places", "posts"]
}

shell

$ rint_create template.html variables.json output.js

output

var db = require('mongojs').connect('basic', ['users', 'places', 'posts'])

rint-property with creating the dynamic code.

data-rint="each"

data-rint="code" allows to create the code loop.

template file

<!DOCTYPE rint>
<script data-rint="variables">
    __rint_project_name__:string
    __rint_collections__:array
</script>
<script data-rint="code">
    var express = require('express')
    var http = require('http')
    
    var app = express()
    var db = require('mongojs').connect('__rint_project_name__', __rint_collections__)
</script>
<script data-rint="each" data-rint-each="__rint_collection__ in __rint_collections__">
    app.get('/__rint_collection__', function (request, response) {
        db.__rint_collection__.find(function (error, results) {
            response.json(error || result)
        })
    })    
    
    app.get('/__rint_collection__/:id', function (request, response) {
      db.__rint_collection__.findOne({
          _id: db.ObjectId(request.param('id'))
      }, function (error, result) {
          response.json(error || result)
      })
    })
</script>
<script data-rint="code">
    http.createServer(app).listen(3000)
</script>

configuration file

{
    "__rint_project_name__": "basic",
    "__rint_collections__": ["users", "posts"]
}

output file

var express = require('express')
var http = require('http')

var app = express()
var db = require('mongojs').connect('basic', ['users', 'posts'])

app.get('/users', function (request, response) {
    db.users.find(function (error, results) {
        response.json(error || result)
    })
})    

app.get('/users/:id', function (request, response) {
  db.users.findOne({
      _id: db.ObjectId(request.param('id'))
  }, function (error, result) {
      response.json(error || result)
  })
})

app.get('/posts', function (request, response) {
    db.posts.find(function (error, results) {
        response.json(error || result)
    })
})    

app.get('/posts/:id', function (request, response) {
  db.posts.findOne({
      _id: db.ObjectId(request.param('id'))
  }, function (error, result) {
      response.json(error || result)
  })
})

http.createServer(app).listen(3000)

rint-property with the file system.

data-rint="import"

data-rint="export"

data-rint="export" helps to create a file and import it with replacement. It must be userd with data-rint-export="__filename__" and data-rint-replace="__code__".

data-rint="imports"

template file

configuration file

output

data-rint="exports"

data-rint="exports" helps to create files and import it with replacement. It must be userd with data-rint-each="__item__ in __items__", data-rint-export="__filename__" and data-rint-replace="__code__".

template file

<!DOCTYPE rint>
<script data-rint="variables">
    __rint_project_name__:string
    __rint_collections__:array
</script>
<script data-rint="code">
    var express = require('express')
    var http = require('http')
    
    var app = express()
    var db = require('mongojs').connect('__rint_project_name__', __rint_collections__)
</script>
<script
    data-rint="each"
    data-rint-each="__rint_collection__ in __rint_collections__"
    data-rint-exports="__rint_collection__.js"
    data-rint-replacement="require('./__rint_collection__').active(app, db)">
    exports.active = function (app, db) {
        app.get('/__rint_collection__', function (request, response) {
            db.__rint_collection__.find(function (error, results) {
                response.json(error || result)
            })
        })    
        
        app.get('/__rint_collection__/:id', function (request, response) {
          db.__rint_collection__.findOne({
              _id: db.ObjectId(request.param('id'))
          }, function (error, result) {
              response.json(error || result)
          })
        })
    }
</script>
<script data-rint="code">
    http.createServer(app).listen(3000)
</script>

configuration file

{
    "__rint_project_name__": "basic",
    "__rint_collections__": ["users", "posts"]
}

output

var express = require('express')
var http = require('http')

var app = express()
var db = require('mongojs').connect('basic', ['users', 'posts'])

require('./users').active(app, db)
require('./posts').active(app, db)

http.createServer(app).listen(3000)

users.js

exports.active = function (app, db) {
    app.get('/users', function (request, response) {
        db.users.find(function (error, results) {
            response.json(error || result)
        })
    })    
    
    app.get('/users/:id', function (request, response) {
      db.users.findOne({
          _id: db.ObjectId(request.param('id'))
      }, function (error, result) {
          response.json(error || result)
      })
    })
}

posts

exports.active = function (app, db) {
    app.get('/posts', function (request, response) {
        db.posts.find(function (error, results) {
            response.json(error || result)
        })
    })    
    
    app.get('/posts/:id', function (request, response) {
      db.posts.findOne({
          _id: db.ObjectId(request.param('id'))
      }, function (error, result) {
          response.json(error || result)
      })
    })
}

rint-property about supporting the project.

Template Based Programming01

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.