Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
feat(releases): initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hypeJunction committed Mar 19, 2018
0 parents commit aaa8156
Show file tree
Hide file tree
Showing 21 changed files with 671 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .gitattributes
@@ -0,0 +1,21 @@
# Auto detect text files and perform LF normalization
* text=auto

*.cs text diff=csharp
*.java text diff=java
*.html text diff=html
*.css text
*.js text
*.sql text

*.csproj text merge=union
*.sln text merge=union eol=crlf

*.docx diff=astextplain
*.DOCX diff=astextplain

# absolute paths are ok, as are globs
/**/postinst* text eol-lf

# paths that don't start with / are treated relative to the .gitattributes folder
relative/path/*.txt text eol-lf
13 changes: 13 additions & 0 deletions .gitignore
@@ -0,0 +1,13 @@
#Ignore files that will need to be changed locally
.DS_Store
robots.txt
/nbproject/
/.sass-cache/
/node_modules/
/build/
/releases/
/vendor/
/mod/
composer.lock
Gemfile.lock
yarn.lock
Empty file added CHANGELOG.md
Empty file.
159 changes: 159 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,159 @@
module.exports = function (grunt) {

var package = grunt.file.readJSON('package.json');

// Project configuration.
grunt.initConfig({
pkg: package,
// Bump version numbers
version: {
pkg: {
src: ['package.json', 'composer.json'],
},
manifest: {
options: {
pkg: grunt.file.readJSON('package.json'),
prefix: '\<version type=\"dist\"\>'
},
src: ['manifest.xml'],
}
},
clean: {
release: {
src: ['build/', 'releases/', 'mod/', 'vendor/', 'composer.lock']
}
},
copy: {
release: {
src: [
'**',
'!**/.git*',
'!releases/**',
'!build/**',
'!mod/**',
'!node_modules/**',
'!package.json',
'!config.rb',
'!sass/**',
'!tests/**',
'!composer.json',
'!composer.lock',
'!package.json',
'!phpunit.xml',
'!Gruntfile.js',
'!Gemfile',
'!Gemfile.lock'
],
dest: 'build/',
expand: true
},
},
compress: {
release: {
options: {
archive: 'releases/<%= pkg.name %>-<%= pkg.version %>.zip'
},
cwd: 'build/',
src: ['**/*'],
dest: '<%= pkg.name %>/',
expand: true
}
},
gitcommit: {
release: {
options: {
message: 'chore(build): release <%= pkg.version %>',
},
files: {
src: ["composer.json", "manifest.xml", "package.json", "CHANGELOG.md"],
}
},
},
gitfetch: {
release: {
all: true
}
},
gittag: {
release: {
options: {
tag: '<%= pkg.version %>',
message: 'Release <%= pkg.version %>'
}
}
},
gitpush: {
release: {
},
release_tags: {
options: {
tags: true
}
}
},
gh_release: {
options: {
token: process.env.GITHUB_TOKEN,
repo: package.repository.repo,
owner: package.repository.owner
},
release: {
tag_name: '<%= pkg.version %>',
name: 'Release <%= pkg.version %>',
body: grunt.file.read('release.md'),
draft: false,
prerelease: false,
asset: {
name: '<%= pkg.name %>-<%= pkg.version %>.zip',
file: 'releases/<%= pkg.name %>-<%= pkg.version %>.zip',
'Content-Type': 'application/zip'
}
}
},
conventionalChangelog: {
options: {
changelogOpts: {
// conventional-changelog options go here
preset: 'angular'
}
},
release: {
src: 'CHANGELOG.md'
}

}
});
// Load all grunt plugins here
grunt.loadNpmTasks('grunt-version');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-composer');
grunt.loadNpmTasks('grunt-conventional-changelog');
grunt.loadNpmTasks('grunt-git');
grunt.loadNpmTasks('grunt-gh-release');

grunt.registerTask('readpkg', 'Read in the package.json file', function () {
grunt.config.set('pkg', grunt.file.readJSON('package.json'));
});

// Release task
grunt.registerTask('release', function (n) {
var n = n || 'patch';
grunt.task.run([
'version::' + n,
'readpkg',
'conventionalChangelog:release',
'gitfetch:release',
'gitcommit:release',
'gittag:release',
'gitpush:release',
'gitpush:release_tags',
'clean:release',
'composer:install:no-dev:prefer-dist',
'copy:release',
'compress:release',
'gh_release',
]);
});
};
29 changes: 29 additions & 0 deletions README.md
@@ -0,0 +1,29 @@
hypeAjax
========

Utilities for AJAX requests

* Deferred view rendering


## Usage

To defer view rendering, simply add `'deferred' => true` to view vars.

```php
echo elgg_view('my_view', [
// tells the view system to defer view render
'deferred' => true,

// if set to false, placeholder will not be rendered
// if set to a value, that value will be used as the placeholder
// if not set, default ajax loader will be used
'placeholder' => false,

// you can pass other view vars, as you would with normal views
// various Elgg data will be serialized and available to the deferred view
// some of the values may need to be wrapped into a Serializable instance
'entity' => get_entity(123),
'user' => get_user(234),
]);
```
8 changes: 8 additions & 0 deletions autoloader.php
@@ -0,0 +1,8 @@
<?php

$path = __DIR__;

if (file_exists("{$path}/vendor/autoload.php")) {
// check if composer dependencies are distributed with the plugin
require_once "{$path}/vendor/autoload.php";
}
26 changes: 26 additions & 0 deletions classes/hypeJunction/Ajax/CapturePageContext.php
@@ -0,0 +1,26 @@
<?php

namespace hypeJunction\Ajax;

use Elgg\Hook;

class CapturePageContext {

/**
* Store page-related information in the client-site data
* This information will be used to restore context
* and validate request signature, when /data endpoints are
* accessed
*
* @elgg_plugin_hook elgg.data page
*
* @param Hook $hook Hook
*
* @return array
*/
public function __invoke(Hook $hook) {
$return = $hook->getValue();
$return['context'] = Context::capture();
return $return;
}
}
82 changes: 82 additions & 0 deletions classes/hypeJunction/Ajax/Context.php
@@ -0,0 +1,82 @@
<?php

namespace hypeJunction\Ajax;

use Elgg\BadRequestException;
use Elgg\Request;

class Context {

/**
* Get context data
* @return array
*/
public static function capture() {

$logged_in_user_guid = elgg_get_logged_in_user_guid();
$page_owner_guid = elgg_get_page_owner_guid();

$contexts = elgg_get_context_stack();
$input = _elgg_services()->request->getParams();
$input = array_filter($input, function($e) {
return !is_null($e);
});
$viewtype = elgg_get_viewtype();
$ts = time();

$data = serialize([$logged_in_user_guid, $page_owner_guid, $contexts, $input, $viewtype, $ts]);
$mac = elgg_build_hmac($data)->getToken();

return [
'user' => $logged_in_user_guid,
'page_owner' => $page_owner_guid,
'context_stack' => $contexts,
'input' => $input,
'viewtype' => $viewtype,
'ts' => $ts,
'mac' => $mac,
];
}

/**
* Prevent unsigned requests to data endpoints
*
* @param Request $request Request
* @param string $name Name of the query element that contains context info
*
* @return bool
* @throws BadRequestException
*
* @todo Expire requests after x seconds
*/
public static function restore(Request $request, $name = '__context') {

$logged_in_user_guid = $request->elgg()->session->getLoggedInUserGuid();

$context = (array) $request->getParam($name, []);

$page_owner_guid = (int) elgg_extract('page_owner', $context);
$contexts = (array) elgg_extract('context_stack', $context);
$input = (array) elgg_extract('input', $context, []);
$viewtype = elgg_extract('viewtype', $context);
$ts = (int) elgg_extract('ts', $context);
$signature = elgg_extract('mac', $context);

$data = serialize([$logged_in_user_guid, $page_owner_guid, $contexts, $input, $viewtype, $ts]);
$mac = elgg_build_hmac($data);

if (!$mac->matchesToken($signature)) {
throw new BadRequestException("Request signature is invalid");
}

elgg_set_context_stack($contexts);
elgg_set_page_owner_guid($page_owner_guid);

foreach ($input as $key => $value) {
$request->setParam($key, $value);
}

return true;
}

}
39 changes: 39 additions & 0 deletions classes/hypeJunction/Ajax/DeferViewRendering.php
@@ -0,0 +1,39 @@
<?php

namespace hypeJunction\Ajax;

use Elgg\Hook;

class DeferViewRendering {

/**
* Defer view rendering by outputing a placeholder
*
* @elgg_plugin_hook view_vars all
*
* @param Hook $hook Hook
*
* @return array
*/
public function __invoke(Hook $hook) {

$vars = $hook->getValue();

if (empty($vars['deferred'])) {
return;
}

unset($vars['deferred']);

$placeholder = elgg_extract('placeholder', $vars);
unset($vars['placeholder']);

$vars['__view_output'] = elgg_view('ajax/placeholder', [
'view' => $hook->getType(),
'payload' => $vars,
'placeholder' => $placeholder,
]);

return $vars;
}
}

0 comments on commit aaa8156

Please sign in to comment.