-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from zendesk/likun/commonjs_support
APPS-1524 As an App developer I expect CommonJS Support in Apps
- Loading branch information
Showing
17 changed files
with
204 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,36 @@ | ||
(function() { | ||
with( require('apps/framework/app_scope') ) { | ||
with( ZendeskApps.AppScope.create() ) { | ||
<% unless modules.nil? %> | ||
require.modules = { | ||
<% modules.each do |path, content| %> | ||
'<%= path %>': function(exports, require, module) { | ||
<%= content %> | ||
}, | ||
<% end %> | ||
eom: undefined | ||
}; | ||
<% end %> | ||
|
||
var source = <%= source %>; | ||
var source = <%= source %>; | ||
|
||
ZendeskApps[<%= name.to_json %>] = ZendeskApps.defineApp(source) | ||
.reopenClass({ location: <%= location.to_json %> }) | ||
.reopen({ | ||
assetUrlPrefix: <%= asset_url_prefix.to_json %>, | ||
appClassName: <%= app_class_name.to_json %>, | ||
author: { | ||
name: <%= author[:name].to_json %>, | ||
email: <%= author[:email].to_json %> | ||
}, | ||
translations: <%= translations.to_json %>, | ||
templates: <%= templates.to_json %>, | ||
frameworkVersion: <%= framework_version.to_json %> | ||
}); | ||
var app = ZendeskApps.defineApp(source) | ||
.reopenClass({ location: <%= location.to_json %> }) | ||
.reopen({ | ||
assetUrlPrefix: <%= asset_url_prefix.to_json %>, | ||
appClassName: <%= app_class_name.to_json %>, | ||
author: { | ||
name: <%= author[:name].to_json %>, | ||
email: <%= author[:email].to_json %> | ||
}, | ||
translations: <%= translations.to_json %>, | ||
templates: <%= templates.to_json %>, | ||
frameworkVersion: <%= framework_version.to_json %>, | ||
}); | ||
|
||
} | ||
|
||
ZendeskApps[<%= name.to_json %>].install({"id": <%= app_id %>, "app_id": <%= app_id %>, "settings": <%= settings.to_json %>}); | ||
ZendeskApps[<%= name.to_json %>] = app; | ||
} | ||
|
||
ZendeskApps[<%= name.to_json %>].install({"id": <%= app_id %>, "app_id": <%= app_id %>, "settings": <%= settings.to_json %>}); | ||
}()); | ||
|
||
ZendeskApps.trigger && ZendeskApps.trigger('ready'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var a = { | ||
name: 'This is A' | ||
}; | ||
|
||
module.exports = a; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var b = { | ||
name: 'This is B' | ||
}; | ||
|
||
module.exports = b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
h1 { | ||
color: red; | ||
span { | ||
color: green; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(function() { | ||
|
||
return { | ||
events: { | ||
'app.activated':'doSomething' | ||
}, | ||
|
||
doSomething: function() { | ||
console.log("Invalid app"); | ||
} | ||
}; | ||
|
||
}()); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var b = {} | ||
module.exports = b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "ABC", | ||
"author": { | ||
"name": "John Smith", | ||
"email": "[email protected]" | ||
}, | ||
"defaultLocale": "en", | ||
"private": true, | ||
"location": "ticket_sidebar", | ||
"frameworkVersion": "0.5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<header> | ||
<span class="logo"/> | ||
<h3>{{setting "name"}}</h3> | ||
</header> | ||
<section data-main/> | ||
<footer> | ||
<a href="mailto:{{author.email}}"> | ||
{{author.name}} | ||
</a> | ||
</footer> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"app": { | ||
"name": "Buddha Machine" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
describe 'files' do | ||
it 'should return all the files within the app folder excluding files in tmp folder' do | ||
@package.files.map(&:relative_path).should =~ %w(app.css app.js assets/logo-small.png assets/logo.png manifest.json templates/layout.hdbs translations/en.json) | ||
@package.files.map(&:relative_path).should =~ %w(app.css app.js assets/logo-small.png assets/logo.png lib/a.js lib/a.txt lib/nested/b.js manifest.json templates/layout.hdbs translations/en.json) | ||
end | ||
|
||
it 'should error out when manifest is missing' do | ||
|
@@ -30,6 +30,21 @@ | |
end | ||
end | ||
|
||
describe 'lib_files' do | ||
it 'should return all the javascript files in the lib folder within the app folder' do | ||
@package.lib_files.map(&:relative_path).should == %w(lib/a.js lib/nested/b.js) | ||
end | ||
end | ||
|
||
describe 'commonjs_modules' do | ||
it 'should return an object with name value pairs containing the path and code' do | ||
@package.commonjs_modules.should == { | ||
"a.js"=>"var a = {\n name: 'This is A'\n};\n\nmodule.exports = a;\n", | ||
"nested/b.js"=>"var b = {\n name: 'This is B'\n};\n\nmodule.exports = b;\n" | ||
} | ||
end | ||
end | ||
|
||
describe 'manifest_json' do | ||
it 'should return manifest json' do | ||
manifest = @package.manifest_json | ||
|
@@ -46,42 +61,65 @@ | |
describe 'readified_js' do | ||
it 'should generate js ready for installation' do | ||
js = @package.readified_js(nil, 0, 'http://localhost:4567/') | ||
|
||
expected =<<HERE | ||
(function() { | ||
with( require('apps/framework/app_scope') ) { | ||
with( ZendeskApps.AppScope.create() ) { | ||
require.modules = { | ||
'a.js': function(exports, require, module) { | ||
var a = { | ||
name: 'This is A' | ||
}; | ||
module.exports = a; | ||
var source = (function() { | ||
}, | ||
'nested/b.js': function(exports, require, module) { | ||
var b = { | ||
name: 'This is B' | ||
}; | ||
module.exports = b; | ||
}, | ||
eom: undefined | ||
}; | ||
var source = (function() { | ||
return { | ||
a: require('a.js'), | ||
events: { | ||
'app.activated':'doSomething' | ||
}, | ||
doSomething: function() { | ||
console.log(a.name); | ||
} | ||
}; | ||
}()); | ||
; | ||
ZendeskApps["ABC"] = ZendeskApps.defineApp(source) | ||
.reopenClass({ location: "ticket_sidebar" }) | ||
.reopen({ | ||
assetUrlPrefix: "http://localhost:4567/", | ||
appClassName: "app-0", | ||
author: { | ||
name: "John Smith", | ||
email: "[email protected]" | ||
}, | ||
translations: {"app":{\"name\":\"Buddha Machine\"}}, | ||
templates: {"layout":"<style>\\n.app-0 header .logo {\\n background-image: url(\\"http://localhost:4567/logo-small.png\\"); }\\n.app-0 h1 {\\n color: red; }\\n .app-0 h1 span {\\n color: green; }\\n</style>\\n<header>\\n <span class=\\"logo\\"/>\\n <h3>{{setting \\"name\\"}}</h3>\\n</header>\\n<section data-main/>\\n<footer>\\n <a href=\\"mailto:{{author.email}}\\">\\n {{author.name}}\\n </a>\\n</footer>\\n</div>"}, | ||
frameworkVersion: "0.5" | ||
}); | ||
} | ||
ZendeskApps["ABC"].install({"id": 0, "app_id": 0, "settings": {\"title\":\"ABC\"}}); | ||
var app = ZendeskApps.defineApp(source) | ||
.reopenClass({ location: "ticket_sidebar" }) | ||
.reopen({ | ||
assetUrlPrefix: "http://localhost:4567/", | ||
appClassName: "app-0", | ||
author: { | ||
name: "John Smith", | ||
email: "[email protected]" | ||
}, | ||
translations: {"app":{"name":"Buddha Machine"}}, | ||
templates: {"layout":"<style>\\n.app-0 header .logo {\\n background-image: url(\\"http://localhost:4567/logo-small.png\\"); }\\n.app-0 h1 {\\n color: red; }\\n .app-0 h1 span {\\n color: green; }\\n</style>\\n<header>\\n <span class=\\"logo\\"/>\\n <h3>{{setting \\"name\\"}}</h3>\\n</header>\\n<section data-main/>\\n<footer>\\n <a href=\\"mailto:{{author.email}}\\">\\n {{author.name}}\\n </a>\\n</footer>\\n</div>"}, | ||
frameworkVersion: "0.5", | ||
}); | ||
ZendeskApps["ABC"] = app; | ||
} | ||
ZendeskApps["ABC"].install({"id": 0, "app_id": 0, "settings": {"title":"ABC"}}); | ||
}()); | ||
ZendeskApps.trigger && ZendeskApps.trigger('ready'); | ||
|
Oops, something went wrong.