Refactor: Adds Discourse.Utilities.registerViewHelper to register view helpers

This commit is contained in:
Robin Ward 2013-05-29 14:32:39 -04:00
parent 3d0587d8ce
commit 4d5c145198
12 changed files with 23 additions and 66 deletions

View file

@ -1,14 +0,0 @@
/**
Inserts a rich code editor
@method aceEditor
@for Handlebars
**/
Ember.Handlebars.registerHelper('aceEditor', function(options) {
var hash = options.hash,
types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, Discourse.AceEditorView, options);
});

View file

@ -57,4 +57,4 @@ Discourse.AceEditorView = Discourse.View.extend({
}
});
Discourse.Utilities.registerViewHelper('aceEditor', Discourse.AceEditorView);

View file

@ -29,6 +29,19 @@ Discourse.Utilities = {
}
},
/*
Register a view class as a helper
*/
registerViewHelper: function(helperName, helperClass) {
Ember.Handlebars.registerHelper(helperName, function(options) {
var hash = options.hash,
types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, helperClass, options);
});
},
// Create a badge like category link
categoryLink: function(category) {
if (!category) return "";

View file

@ -56,51 +56,6 @@ Handlebars.registerHelper('categoryLink', function(property, options) {
return new Handlebars.SafeString(Discourse.Utilities.categoryLink(category));
});
/**
Inserts a Discourse.TextField to allow the user to enter information.
@method textField
@for Handlebars
**/
Ember.Handlebars.registerHelper('textField', function(options) {
var hash = options.hash,
types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, Discourse.TextField, options);
});
/**
Inserts a Discourse.InputTipView
@method inputTip
@for Handlebars
**/
Ember.Handlebars.registerHelper('inputTip', function(options) {
var hash = options.hash,
types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, Discourse.InputTipView, options);
});
/**
Inserts a Discourse.PopupInputTipView
@method popupInputTip
@for Handlebars
**/
Ember.Handlebars.registerHelper('popupInputTip', function(options) {
var hash = options.hash,
types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, Discourse.PopupInputTipView, options);
});
/**
Produces a bound link to a category

View file

@ -17,7 +17,7 @@
<tr {{bindAttr class="archived"}}>
<td class='main-link'>
<div class='topic-inset'>
{{view Discourse.TopicStatusView topicBinding="this"}}
{{topicStatus topic=this}}
{{{topicLink this}}
{{#if unread}}
<a href="{{unbound lastReadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts unread="unread"}}'>{{unbound unread}}</a>

View file

@ -16,7 +16,7 @@
</div>
{{/if}}
{{view Discourse.TopicStatusView topicBinding="this"}}
{{topicStatus topic=this}}
{{{topicLink this}}}
{{#if unread}}
<a href="{{lastReadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts unread="unread"}}'>{{unread}}</a>

View file

@ -16,7 +16,7 @@
{{else}}
<h1>
{{#if view.topic.fancy_title}}
{{view Discourse.TopicStatusView topicBinding="view.topic"}}
{{topicStatus topic=view.topic}}
<a href='{{unbound view.topic.url}}'>{{{view.topic.fancy_title}}}</a>
{{else}}
{{#if view.topic.errorLoading}}

View file

@ -4,7 +4,7 @@
<h1>
{{#if view.topic.fancy_title}}
{{view Discourse.TopicStatusView topicBinding="view.topic"}}
{{topicStatus topic=view.topic}}
<a class='topic-link' href='{{unbound view.topic.url}}'>{{{view.topic.fancy_title}}}</a>
{{else}}
{{#if view.topic.errorLoading}}

View file

@ -19,4 +19,4 @@ Discourse.TextField = Ember.TextField.extend({
});
Discourse.Utilities.registerViewHelper('textField', Discourse.TextField);

View file

@ -30,4 +30,4 @@ Discourse.InputTipView = Discourse.View.extend({
}
});
Discourse.Utilities.registerViewHelper('inputTip', Discourse.InputTipView);

View file

@ -55,3 +55,5 @@ Discourse.PopupInputTipView = Discourse.View.extend({
}
}
});
Discourse.Utilities.registerViewHelper('popupInputTip', Discourse.PopupInputTipView);

View file

@ -48,3 +48,4 @@ Discourse.TopicStatusView = Discourse.View.extend({
});
Discourse.Utilities.registerViewHelper('topicStatus', Discourse.TopicStatusView);