Skip to content

Commit

Permalink
✨ Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
HapLifeMan committed Aug 29, 2019
0 parents commit c6b9de4
Show file tree
Hide file tree
Showing 12 changed files with 8,865 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
ecmaVersion: 2018,
},
env: {
browser: true,
node: true
},
extends: ['standard'],
rules: {
// allow paren-less arrow functions
'arrow-parens': [2, 'as-needed'],
'no-unused-vars': 2,
'no-unused-expressions': 0, // until false alarm on optional-chaining is fixed
// allow async-await
'generator-star-spacing': 0,
'space-before-function-paren': 2,
// allow debugger during development
'no-debugger': 2,
// do not allow console.logs etc...
'no-console': 2,
'no-var': 2,
'no-dupe-keys': 2,
'key-spacing': 2,
'keyword-spacing': 2,
'spaced-comment': [2, 'always', { block: { exceptions: ['-'] } }],
'comma-dangle': [2, 'always-multiline'],
'capitalized-comments': [2, 'always', { ignoreConsecutiveComments: true, ignorePattern: 'console|return|let|const|if|import|global|eslint|throw|void|try|catch|async|await|this' }],
'multiline-comment-style': [2, 'starred-block'],
'lines-around-comment': [2, { beforeBlockComment: true, beforeLineComment: true }],
'no-multiple-empty-lines': [2, { max: 1 }],
'no-trailing-spaces': 0,
'quote-props': [2, 'as-needed'],
'camelcase': 0,
'no-lonely-if': 2,
'no-empty': 2,
'no-unreachable': 2,
'no-cond-assign': 2,
'multiline-ternary': [2, 'never'],
'padded-blocks': [2, 'always', { allowSingleLineBlocks: true }],
'quotes': [2, 'single', { avoidEscape: true, allowTemplateLiterals: true }],
'curly': 0,
'strict': [2, 'never'],
'object-curly-spacing': [2, 'always'],
'object-curly-newline': [2, { ObjectExpression: { multiline: true } }],
'arrow-body-style': [2, 'as-needed']
},
}
35 changes: 35 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Bug report
about: Create a report to help us improve

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
*.iml
.idea
*.log*
.nuxt
.DS_STORE
dist
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at william.da.silva@outlook.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Thomas Reichling <thomas.reichling@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# TrustBox module for Nuxt

[![npm (scoped with tag)](https://img.shields.io/npm/v/nuxt-trustbox-module/latest.svg?style=flat-square)](https://npmjs.com/package/nuxt-trustbox-module)
[![npm](https://img.shields.io/npm/dt/nuxt-trustbox-module.svg?style=flat-square)](https://npmjs.com/package/nuxt-trustbox-module)

> A NuxtJS module thats injects Trustpilot TrustBox code and provide a `<trustbox />` component
## Table of Contents

* [Requirements](#requirements)
* [Install](#install)
* [Getting Started](#getting-started)
* [i18n Translation](#with-i18n)
* [Warnings](#warnings)

## Requirements

* yarn
* NuxtJS
* NodeJS

## Install

```bash
yarn add nuxt-trustbox-module
```

## Getting Started

Add `nuxt-trustbox-module` to `modules` section of `nuxt.config.js`:

```js
{
modules: [

// Simple usage
'nuxt-trustbox-module',

// With options
['nuxt-trustbox-module', {
businessunitId: 'TRUSTPILOT_BUSINESS_ID',
businessunitName: 'TRUSTPILOT_BUSINESS_NAME',
}],

]
}
```

```vue
<Trustbox
template-id="my_trustbox_template_id"
style-height="150px"
style-width="400px"
theme="dark"
locale="fr-FR" />
```

## i18n Translation

It's very simple to automatically translate the TrustBox if you are using `nuxt-i18n`:

```vue
<Trustbox
template-id="my_trustbox_template_id"
:locale="$i18n.locales.find(l => l.code === $i18n.locale).iso"
:key="$i18n.locale" />
```

> The `key` attribute is very important to refresh the component when the locale is switched.
## Module options

List of possible options in the module which can be passed through the module options or by props:

| Option | Default | Required | Description |
|---------------------|----------|----------|-------------------------------------------------------------------------------------------------------------------|
| businessunitId | `''` | true | Your Trustpilot Business ID, you can find it [here](https://businessapp.b2b.trustpilot.com/#/trustbox/library). |
| businessunitName | `''` | true | Your Trustpilot Business Name/URL, it's what comes after `https://trustpilot.com/review/businessunitName`. |
| templateId | `''` | true | The template ID of the TrustBox. |
| styleHeight | `auto` | false | The height of the TrustBox. |
| styleWidth | `100%` | false | The widrg of the TrustBox. |
| locale | `en-US` | false | The locale to display on the TrustBox into a valid ISO format supported by Trustpilot. |
| theme | `light` | false | The theme of the TrustBox (can be `light` or `dark`). |

> Note that the options passed through `nuxt.config.js` are `pascalCase` while options passed through `props` are `camel-case`.
## Warnings

You may have an error in the console saying:

```
[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.
```

You can solve it by wrapping your TrustBox component with `<client-only>` (or `<no-ssr>` for Nuxt 2.9.0 and lower).
90 changes: 90 additions & 0 deletions lib/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import Vue from 'vue'

Vue.component('trustbox', {

render (h) {

return h('div', {
class: ['trustpilot-widget'],
attrs: {
'data-locale': this.locale,
'data-template-id': this.templateId,
'data-businessunit-id': this.businessunitId,
'data-style-height': this.styleHeight,
'data-style-width': this.styleWidth,
'data-theme': this.theme,
},
}, [
h('a', {
attrs: {
href: this.truspilotPageURL,
target: '_blank',
rel: 'noopener',
},
domProps: { innerHTML: 'Trustpilot' },
}),
])

},

props: {

businessunitId: {
type: String,
default: '<%= options.businessunitId %>',
},

businessunitName: {
type: String,
default: '<%= options.businessunitName %>',
},

templateId: {
type: String,
required: true,
},

locale: {
type: String,
default: '<%= options.locale %>',
},

styleHeight: {
type: String,
default: '<%= options.styleHeight %>',
},

styleWidth: {
type: String,
default: '<%= options.styleWidth %>',
},

theme: {
type: String,
default: '<%= options.theme %>',
validate: () => ['dark', 'light'].includes('<%= options.theme %>'),
},

},

mounted () {

if (window.Trustpilot)
this.$nextTick(() => window.Trustpilot.loadFromElement(this.$el))

},

computed: {

truspilotPageURL () {

const locale = this.locale.split('-')[0]
const prefix = (locale !== 'en' ? `${locale}.` : '')

return `https://${prefix}trustpilot.com/review/${this.businessunitName}`

},

},

})
Loading

0 comments on commit c6b9de4

Please sign in to comment.