Skip to content

Commit

Permalink
Simple mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
fajardm committed Apr 23, 2017
1 parent 7446f85 commit 3d6c6c7
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ jspm_packages

# Optional REPL history
.node_repl_history

# Jetbrains
.idea/
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require('path');
const express = require('express');

const app = express();

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

app.get('/', (req, res) => res.render('index'));

app.listen(3000, () => {
// eslint-disable-next-line no-console
console.log('Example app listening on port 3000!');
});
36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "pug-form-helper",
"version": "1.0.0",
"description": "create form helper using pug",
"main": "index.js",
"scripts": {
"test": "test"
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/fajardm/pug-form-helper.git"
},
"keywords": [
"pug",
"form",
"helper",
"nodejs"
],
"author": "[email protected]",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/fajardm/pug-form-helper/issues"
},
"homepage": "https://github.com/fajardm/pug-form-helper#readme",
"dependencies": {
"express": "^4.15.2",
"pug": "^2.0.0-beta.12"
},
"devDependencies": {
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3"
}
}
5 changes: 5 additions & 0 deletions views/index.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../views/mixins/form

+text_field({name: "email", type: "email"})
br
+select_tag({name: 'address', items: ['item 1', 'item 2', 'item 3']})
26 changes: 26 additions & 0 deletions views/mixins/form.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
- Input field
- @params {object} params
//
mixin text_field (params)
- const name = params.name ? params.name : ''
- const label = params.label ? params.label : name
- const placeholder = params.placeholder ? params.placeholder : label
- const type = params.type ? params.type : 'text'
.form-group
label(for=name) #{label}
input.form-control(id=name, name=name, type=type, placeholder=placeholder)

//
- Select tag
- @params {object} params
//
mixin select_tag (params)
- const name = params.name ? params.name : ''
- const label = params.label ? params.label : name
- const items = Array.isArray(params.items) ? params.items : [params.items]
.form-group
label(for=name) #{label}
select.form-control(id=name, name=name)
each item in items
option #{item}

0 comments on commit 3d6c6c7

Please sign in to comment.