urturn-cli 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +12 -0
- data/Rakefile +2 -0
- data/bin/urturn +87 -0
- data/lib/expression_template/__template__.css.erb +13 -0
- data/lib/expression_template/__template__.js.erb +41 -0
- data/lib/expression_template/__template___editor.css.erb +4 -0
- data/lib/expression_template/__template___editor.js.erb +50 -0
- data/lib/expression_template/editor.html.erb +16 -0
- data/lib/expression_template/expression.json.erb +21 -0
- data/lib/expression_template/player.html.erb +10 -0
- data/lib/webdoc-cli/authenticate.rb +71 -0
- data/lib/webdoc-cli/expression_rest_client.rb +173 -0
- data/lib/webdoc-cli/version.rb +5 -0
- data/lib/webdoc-cli.rb +17 -0
- data/urturn-cli.gemspec +26 -0
- metadata +194 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Olivier Amblet
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Develop and Deploy Webdoc Expression
|
2
|
+
|
3
|
+
## Build and install the command line tool
|
4
|
+
|
5
|
+
You need to install webdoc command-line tool, a wrapper around the webdoc REST API to develop expression. Both are considered experimental.
|
6
|
+
|
7
|
+
git clone
|
8
|
+
cd webdoc-cli
|
9
|
+
gem build webdoc-cli.gemspec
|
10
|
+
gem install webdoc-cli-x.y.z.gem
|
11
|
+
|
12
|
+
Have a look at http://dev-wd.webdoc.com/docs#tab_expression to learn more.
|
data/Rakefile
ADDED
data/bin/urturn
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'gli'
|
4
|
+
require 'webdoc-cli'
|
5
|
+
|
6
|
+
|
7
|
+
include GLI::App
|
8
|
+
|
9
|
+
program_desc "Command Line to access Webdoc API"
|
10
|
+
|
11
|
+
flag [:h, :host], :default_value => 'w:d@dev-wd.webdoc.com'
|
12
|
+
|
13
|
+
pre do |global_options, command, options, args|
|
14
|
+
Webdoc::Cli.host = global_options[:host]
|
15
|
+
@client = Webdoc::Cli::ExpressionRestClient.new
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Create a new expression"
|
19
|
+
command 'expression:new' do |c|
|
20
|
+
c.action do |global_options,options,args|
|
21
|
+
name = args[0]
|
22
|
+
if name.nil?
|
23
|
+
Webdoc::Cli.cmd.say "Usage: webdoc expression:new NAME"
|
24
|
+
else
|
25
|
+
@client.create name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Deploy a new version of your expression"
|
31
|
+
command 'expression:deploy' do |c|
|
32
|
+
c.action do |global_options,options,args|
|
33
|
+
path = (args.count > 0 ? args[0] : '.')
|
34
|
+
@client.deploy path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
desc "Show an expression list"
|
40
|
+
command 'expression:list' do |c|
|
41
|
+
c.action do |global_options,options,args|
|
42
|
+
@client.list
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Show an expression details"
|
47
|
+
command 'expression:show' do |c|
|
48
|
+
c.action do |global_options,options,args|
|
49
|
+
name = args[0]
|
50
|
+
if name.nil?
|
51
|
+
Webdoc::Cli.cmd.say "Usage: webdoc expression:show NAME"
|
52
|
+
else
|
53
|
+
@client.show name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "Migrate document belongins to your expressions"
|
59
|
+
command 'expression:migrate' do |c|
|
60
|
+
c.action do |global_options,options,args|
|
61
|
+
name, v0, v1 = args[0..2]
|
62
|
+
if v1.nil?
|
63
|
+
Webdoc::Cli.cmd.say "Usage: webdoc expression:migrate NAME V0 V1"
|
64
|
+
Webdoc::Cli.cmd.say " NAME expression system name"
|
65
|
+
Webdoc::Cli.cmd.say " V0 document using this version will be migrated"
|
66
|
+
Webdoc::Cli.cmd.say " Accepted format: ~1, ~1.2, 1.0.0, 1.2.1"
|
67
|
+
Webdoc::Cli.cmd.say " V1 expression version to use for all documents using V0"
|
68
|
+
Webdoc::Cli.cmd.say " Accepted format: 1.2.2"
|
69
|
+
Webdoc::Cli.cmd.say "\nExamples:"
|
70
|
+
Webdoc::Cli.cmd.say "Migrate all document using expression hello_world between version 1.1.0 and 1.1.7 to version 1.1.8"
|
71
|
+
Webdoc::Cli.cmd.say " $ webdoc expression migrate hello_world '~1.1' '1.1.8'"
|
72
|
+
Webdoc::Cli.cmd.say "Migrate all document using expression hello_world at version 1.1.6 to version 1.1.8"
|
73
|
+
Webdoc::Cli.cmd.say " $ webdoc expression migrate hello_world '1.1.6' '1.1.8'"
|
74
|
+
else
|
75
|
+
@client.migrate name, v0, v1
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
desc "Remove authentication information"
|
81
|
+
command 'disconnect' do |c|
|
82
|
+
c.action do |global_options,options,args|
|
83
|
+
Webdoc::Cli.logout()
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
exit run(ARGV)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* Describe your expression styles below.
|
3
|
+
*
|
4
|
+
* /!\ IMPORTANT NOTE
|
5
|
+
* Do not use #id selector as your expression markup can be displayed multiple time
|
6
|
+
* in the same HTML page. Use .class selectors instead.
|
7
|
+
*/
|
8
|
+
|
9
|
+
|
10
|
+
div.picture img {
|
11
|
+
width: 100%;
|
12
|
+
height: auto;
|
13
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/**
|
2
|
+
* This file let you describe your javascript library. The convention
|
3
|
+
* is to puts all your code in the camelcased version of your expression system name.
|
4
|
+
*
|
5
|
+
* /!\ Your expression might be loaded multiple time in the
|
6
|
+
* same page so you should always limit your DOM queries to
|
7
|
+
* expression.getElement().
|
8
|
+
*/
|
9
|
+
|
10
|
+
var <%= system_name.gsub(/\-/,'_').camelcase %> = function(expression){
|
11
|
+
this.expression = expression;
|
12
|
+
this.imageWrapper = expression.getElement().querySelector('div.picture');
|
13
|
+
this.nameWrapper = expression.getElement().querySelector('span.name');
|
14
|
+
|
15
|
+
var self = this;
|
16
|
+
// display the image.
|
17
|
+
this.expression.items.find('picture', function(imageResource) {
|
18
|
+
if(imageResource){
|
19
|
+
self.displayImage(imageResource);
|
20
|
+
}
|
21
|
+
});
|
22
|
+
|
23
|
+
// display the name.
|
24
|
+
this.expression.items.find('name', function(item) {
|
25
|
+
if(self.nameWrapper && item){
|
26
|
+
self.nameWrapper.innerHTML = item.value;
|
27
|
+
}
|
28
|
+
});
|
29
|
+
};
|
30
|
+
|
31
|
+
<%= system_name.gsub(/\-/,'_').camelcase %>.prototype.displayImage = function(imageResource) {
|
32
|
+
if (!this.img) {
|
33
|
+
this.img = document.createElement('img');
|
34
|
+
this.imageWrapper.appendChild(this.img);
|
35
|
+
var self = this;
|
36
|
+
this.img.addEventListener('load', function(event){
|
37
|
+
self.expression.container.autoResize();
|
38
|
+
});
|
39
|
+
}
|
40
|
+
this.img.src = imageResource.url;
|
41
|
+
};
|
@@ -0,0 +1,50 @@
|
|
1
|
+
// Editor expression script
|
2
|
+
|
3
|
+
<%= system_name.gsub(/\-/,'_').camelcase %>.prototype.enableEditing = function() {
|
4
|
+
this.chooseImageButton = this.expression.getElement().querySelector('button.choose_image');
|
5
|
+
this.nameEditor = this.expression.getElement().querySelector('input.name_editor');
|
6
|
+
|
7
|
+
// open image dialog when user click on the button.
|
8
|
+
this.chooseImageButton.addEventListener('click', this.bindChooseImage());
|
9
|
+
|
10
|
+
// redefine displayImage() to open image dialog when user click on the image.
|
11
|
+
var playerDisplayImage = this.displayImage;
|
12
|
+
this.displayImage = function(imageResource) {
|
13
|
+
playerDisplayImage.call(this, imageResource);
|
14
|
+
this.editorDisplayImage();
|
15
|
+
}
|
16
|
+
if(this.img){
|
17
|
+
this.editorDisplayImage();
|
18
|
+
}
|
19
|
+
|
20
|
+
var self = this;
|
21
|
+
// display text in editor
|
22
|
+
this.expression.items.find('name', function(item){
|
23
|
+
if(item){
|
24
|
+
self.nameEditor.value = item.value;
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
// save text on post
|
29
|
+
this.expression.post(function(doPostCallback){
|
30
|
+
self.expression.items.save('name', {:value => self.nameEditor.value}, function(){
|
31
|
+
doPostCallback();
|
32
|
+
});
|
33
|
+
});
|
34
|
+
};
|
35
|
+
|
36
|
+
<%= system_name.gsub(/\-/,'_').camelcase %>.prototype.bindChooseImage = function() {
|
37
|
+
var self = this;
|
38
|
+
return function(event) {
|
39
|
+
self.expression.medias.imageDialog(function(imageResource) {
|
40
|
+
// Directly save image upon selection
|
41
|
+
self.expression.items.save('picture', imageResource);
|
42
|
+
self.displayImage(imageResource);
|
43
|
+
});
|
44
|
+
};
|
45
|
+
};
|
46
|
+
|
47
|
+
<%= system_name.gsub(/\-/,'_').camelcase %>.prototype.editorDisplayImage = function() {
|
48
|
+
this.img.addEventListener('click', this.bindChooseImage());
|
49
|
+
this.chooseImageButton.className += ' hidden';
|
50
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="picture">
|
2
|
+
<button class="choose_image">Choose a picture</button>
|
3
|
+
</div>
|
4
|
+
<p class="text">
|
5
|
+
Hello, My name is
|
6
|
+
<input type="text" class="name_editor" placeholder="Enter your name"/>
|
7
|
+
</p>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
// Bootstrap you expression editor
|
11
|
+
WD.Expression.ready(function(expression){
|
12
|
+
// Read more in test.js
|
13
|
+
var <%= system_name.gsub(/\-/,'_').camelcase(:lower) %>Instance = new <%= system_name.gsub(/\-/,'_').camelcase %>(expression);
|
14
|
+
<%= system_name.gsub(/\-/,'_').camelcase(:lower) %>Instance.enableEditing();
|
15
|
+
});
|
16
|
+
</script>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"title":"<%= system_name.titleize %>",
|
3
|
+
"system_name":"<%= system_name %>",
|
4
|
+
"version":"1.0.0",
|
5
|
+
"dependencies": [{
|
6
|
+
"type":"stylesheet",
|
7
|
+
"path":"<%= system_name %>.css"
|
8
|
+
},{
|
9
|
+
"type":"stylesheet",
|
10
|
+
"path":"<%= system_name %>_editor.css",
|
11
|
+
"context":"editor"
|
12
|
+
},{
|
13
|
+
"type":"javascript",
|
14
|
+
"path":"<%= system_name %>.js"
|
15
|
+
},{
|
16
|
+
"type":"javascript",
|
17
|
+
"path":"<%= system_name %>_editor.js",
|
18
|
+
"context":"editor"
|
19
|
+
}]
|
20
|
+
|
21
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<div class="picture"></div>
|
2
|
+
<p class="text">Hello, My name is <span class="name"></span></p>
|
3
|
+
|
4
|
+
<script type="text/javascript">
|
5
|
+
// Bootstrap you expression editor
|
6
|
+
WD.Expression.ready(function(expression){
|
7
|
+
// Read more in test.js
|
8
|
+
var <%= system_name.gsub(/\-/,'_').camelcase(:lower) %>Instance = new <%= system_name.camelcase %>(expression);
|
9
|
+
});
|
10
|
+
</script>
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Webdoc::Cli
|
2
|
+
class << self
|
3
|
+
|
4
|
+
def logout
|
5
|
+
rc = Netrc.read()
|
6
|
+
rc.delete Webdoc::Cli.host
|
7
|
+
rc.save
|
8
|
+
Webdoc::Cli.cmd.say 'session information removed from .netrc'
|
9
|
+
end
|
10
|
+
|
11
|
+
def login
|
12
|
+
rc = Netrc.read
|
13
|
+
perform_authentication rc
|
14
|
+
end
|
15
|
+
|
16
|
+
# Use .netrc to manage authentication token.
|
17
|
+
#
|
18
|
+
# If a token is found, consider the client as authenticated
|
19
|
+
# if a 403 error is catched, it means that maybe the token has expired.
|
20
|
+
# In this case, give it a second try after a new authentication.
|
21
|
+
def authenticate_then(&block)
|
22
|
+
rc = Netrc.read()
|
23
|
+
user, pass = rc[Webdoc::Cli.host]
|
24
|
+
if pass
|
25
|
+
begin
|
26
|
+
do_action(user, pass, &block)
|
27
|
+
return
|
28
|
+
rescue RestClient::ExceptionWithResponse => error
|
29
|
+
# Let the unauthorized exception go on.
|
30
|
+
raise error if error.http_code != 403
|
31
|
+
end
|
32
|
+
end
|
33
|
+
user, pass = perform_authentication(rc)
|
34
|
+
do_action(user, pass, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def do_action(user, pass, &block)
|
39
|
+
headers = {:cookies => {:_webdoc_session => pass}}
|
40
|
+
yield headers
|
41
|
+
end
|
42
|
+
|
43
|
+
def perform_authentication(rc)
|
44
|
+
authenticated = false
|
45
|
+
while !authenticated
|
46
|
+
Webdoc::Cli.cmd.say("<%= color('Webdoc Login', BOLD) %>")
|
47
|
+
email = Webdoc::Cli.cmd.ask("Email: "){ |q| q.validate = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i}
|
48
|
+
pass = Webdoc::Cli.cmd.ask("Password: ") { |q| q.echo = "*" }
|
49
|
+
|
50
|
+
Webdoc::Cli.cmd.say("Proceed to login")
|
51
|
+
begin
|
52
|
+
response = RestClient.post 'https://' + Webdoc::Cli.host + '/login.json',
|
53
|
+
'user[email]' => email,
|
54
|
+
'user[password]' => pass
|
55
|
+
raise "Unable to find authentication token" if response.cookies['_webdoc_session'].nil?
|
56
|
+
authenticated = true
|
57
|
+
rescue RestClient::ExceptionWithResponse => error
|
58
|
+
# catch only the unauthorized exception.
|
59
|
+
raise error if error.http_code != 403
|
60
|
+
Webdoc::Cli.cmd.say("<%= color('Invalid email/password', BOLD) %>")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
# Handle succesful login
|
64
|
+
Webdoc::Cli.cmd.say("Logged in")
|
65
|
+
rc[Webdoc::Cli.host]= email, response.cookies['_webdoc_session']
|
66
|
+
rc.save
|
67
|
+
return email, response.cookies['_webdoc_session']
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
require 'netrc'
|
5
|
+
require 'zip/zip'
|
6
|
+
require 'highline'
|
7
|
+
require 'json'
|
8
|
+
require 'active_support/core_ext/string/inflections'
|
9
|
+
require 'erb'
|
10
|
+
require 'pathname'
|
11
|
+
|
12
|
+
|
13
|
+
module Webdoc
|
14
|
+
module Cli
|
15
|
+
class ExpressionRestClient
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@resource = RestClient::Resource.new 'http://' + Webdoc::Cli.host
|
19
|
+
end
|
20
|
+
|
21
|
+
# Bundle and deploy the expression in the current directory
|
22
|
+
def deploy(path='.')
|
23
|
+
Webdoc::Cli.authenticate_then do |headers|
|
24
|
+
Webdoc::Cli.cmd.say "==> create bundle"
|
25
|
+
bundle(path) do |file|
|
26
|
+
request = RestClient::Request.new(
|
27
|
+
:method => :post,
|
28
|
+
:url => url('/expressions.json'),
|
29
|
+
:cookies => headers[:cookies],
|
30
|
+
:payload => {
|
31
|
+
:multipart => true,
|
32
|
+
:bundle => file
|
33
|
+
}
|
34
|
+
)
|
35
|
+
Webdoc::Cli.cmd.say "==> send bundle to #{Webdoc::Cli.host}"
|
36
|
+
response = handle_request_error { request.execute }
|
37
|
+
json = JSON.parse(response.strip)
|
38
|
+
system_name = json['expression']['system_name']
|
39
|
+
Webdoc::Cli.cmd.say "Expression #{@system_name} has been deployed on #{Webdoc::Cli.host}"
|
40
|
+
Webdoc::Cli.cmd.say "http://#{Webdoc::Cli.host}/#{username}/#{system_name}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def create(system_name)
|
46
|
+
if File.exists?(system_name)
|
47
|
+
Webdoc::Cli.cmd.say "Error: already a folder named #{system_name}."
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
|
51
|
+
binding = template_context system_name
|
52
|
+
|
53
|
+
Dir.mkdir(system_name)
|
54
|
+
root_template = File.join(File.dirname(__FILE__), '..', 'expression_template')
|
55
|
+
['expression.json', 'editor.html', 'player.html', '__template__.js', '__template__.css', '__template___editor.js', '__template___editor.css'].each do |name|
|
56
|
+
template = ERB.new File.read(File.join(root_template, name + '.erb'))
|
57
|
+
File.open(File.join(system_name, name.gsub('__template__', system_name)), 'w') do |f|
|
58
|
+
f.write template.result(binding)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
Webdoc::Cli.cmd.say "Expression #{system_name} has been created: #{File.join(Dir.pwd, system_name)}"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Print the list of expressions manageable by the user.
|
65
|
+
def list
|
66
|
+
Webdoc::Cli.authenticate_then do |headers|
|
67
|
+
response = handle_request_error do
|
68
|
+
RestClient.get(url('/expressions.json'), headers)
|
69
|
+
end
|
70
|
+
list = JSON.parse(response.strip)['expressions']
|
71
|
+
if list.empty?
|
72
|
+
Webdoc::Cli.cmd.say "You manage no expression on #{Webdoc::Cli.host}"
|
73
|
+
else
|
74
|
+
Webdoc::Cli.cmd.say "Managed expression on #{Webdoc::Cli.host}:"
|
75
|
+
list.each do |exp|
|
76
|
+
Webdoc::Cli.cmd.say "- #{exp['system_name']} (#{exp['version']})"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Migrate documents using expression with the given system_name
|
83
|
+
# from version v0 to version v1.
|
84
|
+
def migrate(system_name, v0, v1)
|
85
|
+
Webdoc::Cli.authenticate_then do |headers|
|
86
|
+
response = handle_request_error do
|
87
|
+
Webdoc::Cli.cmd.say "==> start migration of #{system_name} from #{v0} to #{v1} on #{Webdoc::Cli.host}"
|
88
|
+
RestClient.post(url("/#{username}/#{system_name}/migrate/#{v0}/#{v1}.json"), {}, headers)
|
89
|
+
end
|
90
|
+
message = JSON.parse(response.strip)['message']
|
91
|
+
Webdoc::Cli.cmd.say(message)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Print the list of expressions
|
96
|
+
def show(system_name)
|
97
|
+
Webdoc::Cli.authenticate_then do |headers|
|
98
|
+
response = handle_request_error do
|
99
|
+
RestClient.get(url("/#{username}/#{system_name}/all.json"), headers)
|
100
|
+
end
|
101
|
+
list = JSON.parse(response.strip)['expressions']
|
102
|
+
list.each do |exp|
|
103
|
+
date = DateTime.parse(exp['created_at'])
|
104
|
+
date.strftime('%Y/%m/%d %H:%M')
|
105
|
+
Webdoc::Cli.cmd.say "- #{exp['system_name']} (#{exp['version']}): #{date.strftime('%Y/%m/%d %H:%M')}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
def username
|
112
|
+
return @username unless @username.nil?
|
113
|
+
Webdoc::Cli.authenticate_then do |headers|
|
114
|
+
response = handle_request_error do
|
115
|
+
RestClient.get(url("/users/current.json"), headers)
|
116
|
+
end
|
117
|
+
@username = JSON.parse(response.strip)['user']['username']
|
118
|
+
return @username
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def url(path)
|
123
|
+
'http://' + Webdoc::Cli.host + path
|
124
|
+
end
|
125
|
+
|
126
|
+
def handle_request_error
|
127
|
+
begin
|
128
|
+
return yield
|
129
|
+
rescue RestClient::Exception => error
|
130
|
+
Webdoc::Cli.cmd.say "Error (HTML CODE #{error.http_code})"
|
131
|
+
case error.http_code
|
132
|
+
when 422
|
133
|
+
errors = JSON.parse(error.response.strip)['errors']
|
134
|
+
errors.each do |msg|
|
135
|
+
Webdoc::Cli.cmd.say " - #{msg}"
|
136
|
+
end
|
137
|
+
else
|
138
|
+
Webdoc::Cli.cmd.say error.response
|
139
|
+
end
|
140
|
+
rescue => ex
|
141
|
+
Webdoc::Cli.cmd.say "Unexpected Error: #{ex.inspect}"
|
142
|
+
end
|
143
|
+
exit 1
|
144
|
+
end
|
145
|
+
|
146
|
+
# Create a bundle of the expression in the current
|
147
|
+
# directory and yield the resulting Zip file.
|
148
|
+
def bundle(expression_folder)
|
149
|
+
f = Tempfile.new('expression_bundle_')
|
150
|
+
exp_path = Pathname.new(expression_folder)
|
151
|
+
begin
|
152
|
+
Zip::ZipOutputStream.open(f.path) do |z|
|
153
|
+
Dir.glob(File.join(exp_path, '**/*.*')) do |path|
|
154
|
+
if(File.file?(path))
|
155
|
+
zip_path = Pathname.new(path).relative_path_from(exp_path)
|
156
|
+
z.put_next_entry(zip_path)
|
157
|
+
z.print File.read(path)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
yield f
|
162
|
+
ensure
|
163
|
+
f.close
|
164
|
+
f.unlink
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def template_context(system_name)
|
169
|
+
binding
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
data/lib/webdoc-cli.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'highline'
|
2
|
+
|
3
|
+
require "webdoc-cli/version"
|
4
|
+
require "webdoc-cli/authenticate"
|
5
|
+
require "webdoc-cli/expression_rest_client"
|
6
|
+
|
7
|
+
module Webdoc
|
8
|
+
module Cli
|
9
|
+
class << self
|
10
|
+
attr_accessor :host
|
11
|
+
|
12
|
+
def cmd
|
13
|
+
@cmd ||= HighLine.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/urturn-cli.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/webdoc-cli/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Webdoc", "Olivier Amblet"]
|
6
|
+
gem.email = ["olivier.amblet@webdoc.com"]
|
7
|
+
gem.description = %q{Urturn Command Line}
|
8
|
+
gem.summary = %q{Access Urturn through command line}
|
9
|
+
gem.homepage = "http://www.urturn.com"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "urturn-cli"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Webdoc::Cli::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "gli"
|
19
|
+
gem.add_dependency "rest-client"
|
20
|
+
gem.add_dependency "netrc"
|
21
|
+
gem.add_dependency "rake"
|
22
|
+
gem.add_dependency "highline"
|
23
|
+
gem.add_dependency "rubyzip"
|
24
|
+
gem.add_dependency "json"
|
25
|
+
gem.add_dependency "activesupport"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: urturn-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Webdoc
|
9
|
+
- Olivier Amblet
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-12-21 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: gli
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rest-client
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: netrc
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rake
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: highline
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :runtime
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rubyzip
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: json
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: activesupport
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
type: :runtime
|
136
|
+
prerelease: false
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
description: Urturn Command Line
|
144
|
+
email:
|
145
|
+
- olivier.amblet@webdoc.com
|
146
|
+
executables:
|
147
|
+
- urturn
|
148
|
+
extensions: []
|
149
|
+
extra_rdoc_files: []
|
150
|
+
files:
|
151
|
+
- .gitignore
|
152
|
+
- Gemfile
|
153
|
+
- LICENSE
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- bin/urturn
|
157
|
+
- lib/expression_template/__template__.css.erb
|
158
|
+
- lib/expression_template/__template__.js.erb
|
159
|
+
- lib/expression_template/__template___editor.css.erb
|
160
|
+
- lib/expression_template/__template___editor.js.erb
|
161
|
+
- lib/expression_template/editor.html.erb
|
162
|
+
- lib/expression_template/expression.json.erb
|
163
|
+
- lib/expression_template/player.html.erb
|
164
|
+
- lib/webdoc-cli.rb
|
165
|
+
- lib/webdoc-cli/authenticate.rb
|
166
|
+
- lib/webdoc-cli/expression_rest_client.rb
|
167
|
+
- lib/webdoc-cli/version.rb
|
168
|
+
- urturn-cli.gemspec
|
169
|
+
homepage: http://www.urturn.com
|
170
|
+
licenses: []
|
171
|
+
post_install_message:
|
172
|
+
rdoc_options: []
|
173
|
+
require_paths:
|
174
|
+
- lib
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
176
|
+
none: false
|
177
|
+
requirements:
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
|
+
none: false
|
183
|
+
requirements:
|
184
|
+
- - ! '>='
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
requirements: []
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 1.8.24
|
190
|
+
signing_key:
|
191
|
+
specification_version: 3
|
192
|
+
summary: Access Urturn through command line
|
193
|
+
test_files: []
|
194
|
+
has_rdoc:
|