Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make <p> tags optional #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,44 @@
ember install ember-cli-lorem-ipsum
# if ember-cli <= 0.2.2
ember install:addon ember-cli-lorem-ipsum

It provides a helper that makes it easy to add dummy text. The only option that the helper accepts is **length**.

The text will be returned inside a `<p>` tag like this:
It provides a helper that makes it easy to add dummy text.

### Options
Option | Value | Description
--- | --- | ---
length | Number | The length of the text to return (number of characters). *Defaut* 0 (returns the default paragraph )
html | Boolean | Wrap the text in `<p>` tags. *Default* true


If the html option is true, the text will be returned inside a `<p>` tag like this:

<p class="lorem_ipsum">Lorem ipsum.</p>

Otherwise it will return as:

Lorem ipsum.

## Examples

#### no length

{{lorem-ipsum}}

<p class="lorem_ipsum">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

#### length 11

{{lorem-ipsum length=11}}

<p class="lorem_ipsum">Lorem ipsum.</p>

#### length 500

{{lorem-ipsum length=500}}

<p class="lorem_ipsum">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit,.</p>

## Installation

* `git clone` this repository
Expand Down
10 changes: 7 additions & 3 deletions app/helpers/lorem-ipsum.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ember from 'ember';

var originalText =
var originalText =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, '+
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '+
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut '+
Expand All @@ -19,20 +19,24 @@ export function loremIpsum(params, hash) {
text = text.substring(0, hash.length);
} else {
var result = '',
repeatN = hash.length / text.length;
repeatN = hash.length / text.length;

for (var i = 0; i < repeatN; i++) {
result += text;
result += (i === repeatN-1) ? '' : '. ';
}
var remainder = hash.length % text.length;
var remainder = hash.length % text.length;
result += text.substring(0, remainder);
text = result;
}
}

text += '.';

if (hash && hash.html === false) {
return text;
}

return new Ember.Handlebars
.SafeString('<p class="lorem_ipsum">' + text + '</p>');
}
Expand Down