Skip to content

Instantly share code, notes, and snippets.

@geedmo
Last active July 10, 2019 03:36
Show Gist options
  • Save geedmo/5682742 to your computer and use it in GitHub Desktop.
Save geedmo/5682742 to your computer and use it in GitHub Desktop.
Lorem Ipsum generator mixin for Jade (single paragraph)
//- ----------------------------------
//- Usage:
//- include lorem
//- p
//- mixin lorem(25)
//- ----------------------------------
//- new sentece after N words
- var colonEvery = 10
//- 175 words
words = ['consectetur', 'adipiscing', 'elit', 'curabitur', 'vel', 'hendrerit', 'libero', 'eleifend', 'blandit', 'nunc', 'ornare', 'odio', 'ut', 'orci', 'gravida', 'imperdiet', 'nullam', 'purus', 'lacinia', 'a', 'pretium', 'quis', 'congue', 'praesent', 'sagittis', 'laoreet', 'auctor', 'mauris', 'non', 'velit', 'eros', 'dictum', 'proin', 'accumsan', 'sapien', 'nec', 'massa', 'volutpat', 'venenatis', 'sed', 'eu', 'molestie', 'lacus', 'quisque', 'porttitor', 'ligula', 'dui', 'mollis', 'tempus', 'at', 'magna', 'vestibulum', 'turpis', 'ac', 'diam', 'tincidunt', 'id', 'condimentum', 'enim', 'sodales', 'in', 'hac', 'habitasse', 'platea', 'dictumst', 'aenean', 'neque', 'fusce', 'augue', 'leo', 'eget', 'semper', 'mattis', 'tortor', 'scelerisque', 'nulla', 'interdum', 'tellus', 'malesuada', 'rhoncus', 'porta', 'sem', 'aliquet', 'et', 'nam', 'suspendisse', 'potenti', 'vivamus', 'luctus', 'fringilla', 'erat', 'donec', 'justo', 'vehicula', 'ultricies', 'varius', 'ante', 'primis', 'faucibus', 'ultrices', 'posuere', 'cubilia', 'curae', 'etiam', 'cursus', 'aliquam', 'quam', 'dapibus', 'nisl', 'feugiat', 'egestas', 'class', 'aptent', 'taciti', 'sociosqu', 'ad', 'litora', 'torquent', 'per', 'conubia', 'nostra', 'inceptos', 'himenaeos', 'phasellus', 'nibh', 'pulvinar', 'vitae', 'urna', 'iaculis', 'lobortis', 'nisi', 'viverra', 'arcu', 'morbi', 'pellentesque', 'metus', 'commodo', 'ut', 'facilisis', 'felis', 'tristique', 'ullamcorper', 'placerat', 'aenean', 'convallis', 'sollicitudin', 'integer', 'rutrum', 'duis', 'est', 'etiam', 'bibendum', 'donec', 'pharetra', 'vulputate', 'maecenas', 'mi', 'fermentum', 'consequat', 'suscipit', 'aliquam', 'habitant', 'senectus', 'netus', 'fames', 'quisque', 'euismod', 'curabitur', 'lectus', 'elementum', 'tempor', 'risus', 'cras', 'colus', 'miga' ]
//- first letter to uppercase
mixin capitalize(string)
= string.charAt(0).toUpperCase() + string.slice(1)
//- begin a new sentence
mixin beginSentence(string)
= '. '
mixin capitalize(string)
- var maxWords = words.length - 1
//- howmany: number of words in paragraph
//- loremipsum: include the paragraph typical initiation?
mixin lorem(howmany, loremipsum)
//- include lorem ipsum?
if loremipsum || typeof loremipsum == 'undefined'
= 'Lorem ipsum dolor sit amet. '
- for (var i = 0; i < howmany; i++) {
- var nextWord = words[Math.floor((Math.random()*maxWords))]
if (i == 0)
mixin capitalize(nextWord)
else
if ! parseInt(i % colonEvery) && (howmany - i > colonEvery)
mixin beginSentence(nextWord)
else
= ' ' + nextWord
if i == howmany - 1
= '.'
- }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment