REFACTOR: applies discourse core coding practices (#82)
This commit is contained in:
parent
cd82a905ae
commit
270799166b
104
.eslintrc
104
.eslintrc
|
@ -1,105 +1,3 @@
|
|||
{
|
||||
"env": {
|
||||
"jasmine": true,
|
||||
"node": true,
|
||||
"mocha": true,
|
||||
"browser": true,
|
||||
"builtin": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 7,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"globals":
|
||||
{"Ember":true,
|
||||
"jQuery":true,
|
||||
"$":true,
|
||||
"RSVP":true,
|
||||
"Discourse":true,
|
||||
"Em":true,
|
||||
"PreloadStore":true,
|
||||
"Handlebars":true,
|
||||
"I18n":true,
|
||||
"bootbox":true,
|
||||
"module":true,
|
||||
"moduleFor":true,
|
||||
"moduleForComponent":true,
|
||||
"Pretender":true,
|
||||
"sandbox":true,
|
||||
"controllerFor":true,
|
||||
"test":true,
|
||||
"ok":true,
|
||||
"not":true,
|
||||
"expect":true,
|
||||
"equal":true,
|
||||
"visit":true,
|
||||
"andThen":true,
|
||||
"click":true,
|
||||
"currentPath":true,
|
||||
"currentRouteName":true,
|
||||
"currentURL":true,
|
||||
"fillIn":true,
|
||||
"keyEvent":true,
|
||||
"triggerEvent":true,
|
||||
"count":true,
|
||||
"exists":true,
|
||||
"visible":true,
|
||||
"invisible":true,
|
||||
"asyncRender":true,
|
||||
"selectDropdown":true,
|
||||
"asyncTestDiscourse":true,
|
||||
"fixture":true,
|
||||
"find":true,
|
||||
"sinon":true,
|
||||
"moment":true,
|
||||
"start":true,
|
||||
"_":true,
|
||||
"alert":true,
|
||||
"containsInstance":true,
|
||||
"deepEqual":true,
|
||||
"notEqual":true,
|
||||
"define":true,
|
||||
"require":true,
|
||||
"requirejs":true,
|
||||
"hasModule":true,
|
||||
"Blob":true,
|
||||
"File":true},
|
||||
"rules": {
|
||||
"block-scoped-var": 2,
|
||||
"dot-notation": 0,
|
||||
"eqeqeq": [
|
||||
2,
|
||||
"allow-null"
|
||||
],
|
||||
"guard-for-in": 2,
|
||||
"no-bitwise": 2,
|
||||
"no-caller": 2,
|
||||
"no-cond-assign": 0,
|
||||
"no-debugger": 2,
|
||||
"no-empty": 0,
|
||||
"no-eval": 2,
|
||||
"no-extend-native": 2,
|
||||
"no-extra-parens": 0,
|
||||
"no-irregular-whitespace": 2,
|
||||
"no-iterator": 2,
|
||||
"no-loop-func": 2,
|
||||
"no-multi-str": 2,
|
||||
"no-new": 2,
|
||||
"no-plusplus": 0,
|
||||
"no-proto": 2,
|
||||
"no-script-url": 2,
|
||||
"no-sequences": 2,
|
||||
"no-shadow": 2,
|
||||
"no-undef": 2,
|
||||
"no-unused-vars": 2,
|
||||
"no-with": 2,
|
||||
"semi": 2,
|
||||
"strict": 0,
|
||||
"valid-typeof": 2,
|
||||
"wrap-iife": [
|
||||
2,
|
||||
"inside"
|
||||
]
|
||||
},
|
||||
"parser": "babel-eslint"
|
||||
"extends": "eslint-config-discourse"
|
||||
}
|
||||
|
|
|
@ -6,3 +6,4 @@ Gemfile.lock
|
|||
.DS_Store
|
||||
*.swp
|
||||
.rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
|
||||
node_modules
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
export default Ember.Component.extend({
|
||||
router: Ember.inject.service(),
|
||||
|
@ -23,7 +23,7 @@ export default Ember.Component.extend({
|
|||
"router.currentRoute.parent.attributes.category.read_restricted"
|
||||
),
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"router.currentRoute.attributes.__type",
|
||||
"router.currentRoute.attributes.id"
|
||||
)
|
||||
|
@ -33,12 +33,12 @@ export default Ember.Component.extend({
|
|||
}
|
||||
},
|
||||
|
||||
@computed("router.currentRoute.parent.attributes.archetype")
|
||||
@discourseComputed("router.currentRoute.parent.attributes.archetype")
|
||||
isPersonalMessage(topicType) {
|
||||
return topicType === "private_message";
|
||||
},
|
||||
|
||||
@computed("currentUser.groups")
|
||||
@discourseComputed("currentUser.groups")
|
||||
showToGroups(groups) {
|
||||
const currentUser = Discourse.User.current();
|
||||
|
||||
|
@ -67,7 +67,7 @@ export default Ember.Component.extend({
|
|||
return !currentGroups.any(g => noAdsGroups.includes(g));
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"currentCategoryId",
|
||||
"topicTagsDisableAds",
|
||||
"topicListTag",
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
|
||||
const adConfig = Ember.Object.create({
|
||||
"google-adsense": {
|
||||
|
@ -85,7 +82,7 @@ export default AdComponent.extend({
|
|||
* For a given ad placement and optionally a post number if in between posts,
|
||||
* list all ad network names that are configured to show there.
|
||||
*/
|
||||
@computed("placement", "postNumber")
|
||||
@discourseComputed("placement", "postNumber")
|
||||
availableAdTypes(placement, postNumber) {
|
||||
let types = [];
|
||||
const houseAds = this.site.get("house_creatives"),
|
||||
|
@ -167,7 +164,7 @@ export default AdComponent.extend({
|
|||
* in the given ad placement. It handles alternating between house ads
|
||||
* and other ad networks.
|
||||
*/
|
||||
@computed("placement", "availableAdTypes", "needsUpdate")
|
||||
@discourseComputed("placement", "availableAdTypes", "needsUpdate")
|
||||
adComponents(placement, availableAdTypes) {
|
||||
if (
|
||||
!availableAdTypes.includes("house-ad") ||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
||||
const publisherId = Discourse.SiteSettings.adbutler_publisher_id;
|
||||
|
@ -117,7 +114,7 @@ export default AdComponent.extend({
|
|||
}
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel &&
|
||||
|
@ -125,7 +122,7 @@ export default AdComponent.extend({
|
|||
);
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showAfterPost",
|
||||
|
@ -141,7 +138,7 @@ export default AdComponent.extend({
|
|||
);
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
const data = {
|
||||
"topic-list-top": {},
|
||||
|
@ -157,32 +157,32 @@ export default AdComponent.extend({
|
|||
this._super();
|
||||
},
|
||||
|
||||
@computed("amazon_width", "amazon_height")
|
||||
@discourseComputed("amazon_width", "amazon_height")
|
||||
adWrapperStyle(w, h) {
|
||||
return `width: ${w}px; height: ${h}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("mobile_amazon_width", "mobile_amazon_height")
|
||||
@discourseComputed("mobile_amazon_width", "mobile_amazon_height")
|
||||
adWrapperStyleMobile(w, h) {
|
||||
return `width: ${w}px; height: ${h}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("mobile_amazon_width")
|
||||
@discourseComputed("mobile_amazon_width")
|
||||
adTitleStyleMobile(w) {
|
||||
return `width: ${w}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("user_input")
|
||||
@discourseComputed("user_input")
|
||||
userInput(userInput) {
|
||||
return `${userInput}`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("user_input_mobile")
|
||||
@discourseComputed("user_input_mobile")
|
||||
userInputMobile(userInput) {
|
||||
return `${userInput}`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel &&
|
||||
|
@ -190,7 +190,7 @@ export default AdComponent.extend({
|
|||
);
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import { default as computed } from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
const serve_id = Discourse.SiteSettings.carbonads_serve_id,
|
||||
placement = Discourse.SiteSettings.carbonads_placement;
|
||||
|
@ -10,12 +10,12 @@ export default AdComponent.extend({
|
|||
this._super();
|
||||
},
|
||||
|
||||
@computed("serve_id")
|
||||
@discourseComputed("serve_id")
|
||||
url(serveId) {
|
||||
return `//cdn.carbonads.com/carbon.js?serve=${serveId}&placement=${placement}`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel &&
|
||||
|
@ -23,7 +23,7 @@ export default AdComponent.extend({
|
|||
);
|
||||
},
|
||||
|
||||
@computed("showToTrustLevel", "showToGroups", "showOnCurrentPage")
|
||||
@discourseComputed("showToTrustLevel", "showToGroups", "showOnCurrentPage")
|
||||
showAd(showToTrustLevel, showToGroups, showOnCurrentPage) {
|
||||
return (
|
||||
placement &&
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
import { Promise } from "rsvp";
|
||||
|
||||
let _loaded = false,
|
||||
|
@ -108,14 +105,14 @@ export default AdComponent.extend({
|
|||
}
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel && trustLevel > this.siteSettings.codefund_through_trust_level
|
||||
);
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showAfterPost",
|
||||
|
@ -131,7 +128,7 @@ export default AdComponent.extend({
|
|||
);
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
||||
let _loaded = false,
|
||||
|
@ -173,41 +170,41 @@ export default AdComponent.extend({
|
|||
}
|
||||
},
|
||||
|
||||
@computed("ad_width")
|
||||
@discourseComputed("ad_width")
|
||||
isResponsive(adWidth) {
|
||||
return adWidth === "auto";
|
||||
},
|
||||
|
||||
@computed("placement", "showAd")
|
||||
@discourseComputed("placement", "showAd")
|
||||
classForSlot(placement, showAd) {
|
||||
return showAd ? `adsense-${placement}`.htmlSafe() : "";
|
||||
},
|
||||
|
||||
@computed("isResponsive")
|
||||
@discourseComputed("isResponsive")
|
||||
autoAdFormat(isResponsive) {
|
||||
return isResponsive ? "auto".htmlSafe() : false;
|
||||
},
|
||||
|
||||
@computed("ad_width", "ad_height", "isResponsive")
|
||||
@discourseComputed("ad_width", "ad_height", "isResponsive")
|
||||
adWrapperStyle(w, h, isResponsive) {
|
||||
return (isResponsive ? "" : `width: ${w}; height: ${h};`).htmlSafe();
|
||||
},
|
||||
|
||||
@computed("adWrapperStyle", "isResponsive")
|
||||
@discourseComputed("adWrapperStyle", "isResponsive")
|
||||
adInsStyle(adWrapperStyle, isResponsive) {
|
||||
return `display: ${
|
||||
isResponsive ? "block" : "inline-block"
|
||||
}; ${adWrapperStyle}`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel && trustLevel > this.siteSettings.adsense_through_trust_level
|
||||
);
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showAfterPost",
|
||||
|
@ -223,7 +220,7 @@ export default AdComponent.extend({
|
|||
);
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
on
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { on } from "discourse-common/utils/decorators";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
||||
let _loaded = false,
|
||||
|
@ -246,7 +243,7 @@ export default AdComponent.extend({
|
|||
width: Ember.computed.alias("size.width"),
|
||||
height: Ember.computed.alias("size.height"),
|
||||
|
||||
@computed()
|
||||
@discourseComputed
|
||||
size() {
|
||||
return getWidthAndHeight(
|
||||
this.get("placement"),
|
||||
|
@ -255,7 +252,7 @@ export default AdComponent.extend({
|
|||
);
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"siteSettings.dfp_publisher_id",
|
||||
"siteSettings.dfp_publisher_id_mobile",
|
||||
"site.mobileView"
|
||||
|
@ -268,7 +265,7 @@ export default AdComponent.extend({
|
|||
}
|
||||
},
|
||||
|
||||
@computed("placement", "postNumber")
|
||||
@discourseComputed("placement", "postNumber")
|
||||
divId(placement, postNumber) {
|
||||
let slotNum = getNextSlotNum();
|
||||
if (postNumber) {
|
||||
|
@ -278,26 +275,26 @@ export default AdComponent.extend({
|
|||
}
|
||||
},
|
||||
|
||||
@computed("placement", "showAd")
|
||||
@discourseComputed("placement", "showAd")
|
||||
adUnitClass(placement, showAd) {
|
||||
return showAd ? `dfp-ad-${placement}` : "";
|
||||
},
|
||||
|
||||
@computed("width", "height")
|
||||
@discourseComputed("width", "height")
|
||||
adWrapperStyle(w, h) {
|
||||
if (w !== "fluid") {
|
||||
return `width: ${w}px; height: ${h}px;`.htmlSafe();
|
||||
}
|
||||
},
|
||||
|
||||
@computed("width")
|
||||
@discourseComputed("width")
|
||||
adTitleStyleMobile(w) {
|
||||
if (w !== "fluid") {
|
||||
return `width: ${w}px;`.htmlSafe();
|
||||
}
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"publisherId",
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
|
@ -323,14 +320,14 @@ export default AdComponent.extend({
|
|||
);
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel && trustLevel > this.siteSettings.dfp_through_trust_level
|
||||
);
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
|
||||
const adIndex = {
|
||||
topic_list_top: null,
|
||||
|
@ -16,17 +13,17 @@ export default AdComponent.extend({
|
|||
classNameBindings: ["adUnitClass"],
|
||||
adHtml: "",
|
||||
|
||||
@computed("placement", "showAd")
|
||||
@discourseComputed("placement", "showAd")
|
||||
adUnitClass(placement, showAd) {
|
||||
return showAd ? `house-${placement}` : "";
|
||||
},
|
||||
|
||||
@computed("showToGroups", "showAfterPost", "showOnCurrentPage")
|
||||
@discourseComputed("showToGroups", "showAfterPost", "showOnCurrentPage")
|
||||
showAd(showToGroups, showAfterPost, showOnCurrentPage) {
|
||||
return showToGroups && showAfterPost && showOnCurrentPage;
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "discourse-adplugin",
|
||||
"version": "1.0.0",
|
||||
"repository": "git@github.com:discourse/discourse-adplugin.git",
|
||||
"author": "Discourse",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"eslint-config-discourse": "1.1.0"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue