0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Subscribers: Adding subscribe app + tpl + helper

- added new internal app "subscribers"
- app has a template "subscribe.hbs"
- adds a new helper called "form_subscribe"
This commit is contained in:
Hannah Wolfe 2016-04-14 18:33:22 +01:00
parent c41c09ef97
commit 4ca0c67f9c
4 changed files with 112 additions and 0 deletions

View file

@ -0,0 +1,23 @@
var _ = require('lodash'),
path = require('path'),
config = require('../../config'),
router = require('./lib/router'),
// Dirty require
template = require('../../helpers/template');
module.exports = {
activate: function activate(ghost) {
// Correct way to register a helper from an app
ghost.helpers.register('form_subscribe', function formSubscribeHelper(options) {
var data = _.merge({}, options.hash, {
action: path.join(config.paths.subdir, config.routeKeywords.subscribe) + '/'
});
return template.execute('form_subscribe', data, options);
});
},
setupRoutes: function setupRoutes(blogRouter) {
blogRouter.use('/' + config.routeKeywords.subscribe + '/', router);
}
};

View file

@ -0,0 +1,34 @@
var path = require('path'),
express = require('express'),
templates = require('../../../controllers/frontend/templates'),
setResponseContext = require('../../../controllers/frontend/context'),
subscribeRouter = express.Router();
function controller(req, res) {
var defaultView = path.resolve(__dirname, 'views', 'subscribe.hbs'),
paths = templates.getActiveThemePaths(req.app.get('activeTheme')),
data = {};
if (res.error) {
data.error = res.error;
}
setResponseContext(req, res);
if (paths.hasOwnProperty('subscribe.hbs')) {
return res.render('subscribe', data);
} else {
return res.render(defaultView, data);
}
}
// subscribe frontend route
subscribeRouter.route('/')
.get(
controller
)
.post(
controller
);
module.exports = subscribeRouter;
module.exports.controller = controller;

View file

@ -0,0 +1,47 @@
<!doctype html>
<!--[if (IE 8)&!(IEMobile)]><html class="no-js lt-ie9" lang="en"><![endif]-->
<!--[if (gte IE 9)| IEMobile |!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Ghost - Subscribe</title>
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="shortcut icon" href="{{asset "favicon.ico"}}">
<meta http-equiv="cleartype" content="on">
<link rel="stylesheet" type='text/css' href='//fonts.googleapis.com/css?family=Open+Sans:400,300,700'>
<link rel="stylesheet" href="{{asset "ghost.css" ghost="true" minifyInProduction="true"}}" />
</head>
<body>
<div class="gh-app">
<div class="gh-viewport">
<main class="gh-main" role="main">
<div class="gh-flow">
<div class="gh-flow-content-wrap">
<section class="gh-flow-content">
<header>
<h1>Subscribe</h1>
</header>
{{test}}
{{form_subscribe class="gh-signin"}}
</section>
</div>
</div>
</main>
{{#if error}}
<aside class="gh-notifications">
<article class="gh-notification gh-notification-red">
<div id="gh-notification-content">{{error.message}}</div>
</article>
</aside>
{{/if}}
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,8 @@
<form method="post" action="{{action}}" class="{{class}}">
<div class="form-group">
<span class="input-icon icon-mail">
<input type="email" name="email" class="gh-input">
</span>
</div>
<button class="btn btn-blue btn-block" type="submit">Subscribe</button>
</form>