Skip to content

Commit

Permalink
Cut placeholdit
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Jul 6, 2022
1 parent c9170a2 commit 95aa32e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 344 deletions.
71 changes: 1 addition & 70 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,7 @@ Then you just need to call out the tag you want to use.

All placeholder providers expect a width and height to be provided.

One provider we have a templatetag for is [placehold.it](https://placehold.it/).

```html+django
{% placeholdit 400 250 %}
```

<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97250&w=400&h=250">

Another is [placekitten.com](https://placekitten.com/)
One provider is [placekitten.com](https://placekitten.com/)

```html+django
{% placekitten 200 200 %}
Expand Down Expand Up @@ -173,39 +165,6 @@ Here are all the attributes on a ``Story`` object:
|sources|
|credits|
|content|
|image|


#### Image objects

```html+django
{% latimes_image 250 250 as obj %}
<img src="{{ obj.url }}">
<p>Credits: {{ obj.caption }}. ({{ obj.credit }})</p>
```

Which would print out as:

> <img src="https://placeholdit.imgix.net/~text?txtsize=23&bg=cccccc&txt=250%C3%97250&w=250&h=250">
<p>Credits: This is not an image caption. (This is not an image credit)</p>
You give images a custom background color like so:

```html
{% latimes_image 250 250 000000 as obj %}
```

Which would give the image a background color of ```#000000```. If there is no background color set, it will automatically be ```#CCCCCC```.


Here are all the attributes on an ``Image`` object:

|Name|
|:---|
|url|
|credit|
|caption|


#### Quote objects
Expand All @@ -231,34 +190,6 @@ Here are all the attributes on a ``Quote`` object:
|source|


#### Related item lists

Related items link to other similar stories at the bottom of an article. By default, there are 4 related items.

```html+django
{% latimes_related_items as related_items %}
{% for item in related_items %}
<div>
<a href="{{ item.url }}">
<p>{{ item.headline }}</p>
</a>
<a href="{{ item.url }}">
<img src="{{ item.image.url }}">
</a>
</div>
{% endfor %}
```

Here are all the attributes on a `Related` object:

|Name|
|:---|
|headline|
|url|
|image|


### Jabberwocky

["Jabberywocky"](https://en.wikipedia.org/wiki/Jabberwocky) is a 1871 poem by Lewis Carroll, the author of "Alice in Wonderland." Selections can be printed by using the tag below.
Expand Down
57 changes: 0 additions & 57 deletions greeking/latimes_ipsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from django.utils import lorem_ipsum

from . import placeholdit

#
# Objects
#
Expand All @@ -29,7 +27,6 @@ def __init__(
sources,
credits,
content,
image,
):
self.slug = slug
self.headline = headline
Expand All @@ -41,29 +38,6 @@ def __init__(
self.sources = sources
self.credits = credits
self.content = content
self.image = image


class RelatedItem:
"""
A condensed reference to a story.
"""

def __init__(self, headline, url, image):
self.headline = headline
self.url = url
self.image = image


class Image:
"""
An image.
"""

def __init__(self, url, credit, caption):
self.url = url
self.credit = credit
self.caption = caption


class Quote:
Expand Down Expand Up @@ -96,37 +70,6 @@ def get_story():
sources="This is not a source",
credits="This is not a credit",
content=str("\n\n".join(lorem_ipsum.paragraphs(6))),
image=get_image(900),
)


def get_related_items(count=4):
"""
Returns the requested number of boiler plate related items as a list.
"""
defaults = dict(
headline="This is not a headline",
url="http://www.example.com/",
image=get_image(400, 400),
)
return [RelatedItem(**defaults) for x in range(0, count)]


def get_image(
width, height=None, background_color="cccccc", random_background_color=False
):
"""
Returns image with caption, credit, and random background color as requested.
"""
return Image(
url=placeholdit.get_url(
width,
height=height,
background_color=background_color,
random_background_color=random_background_color,
),
credit="This is not an image credit",
caption="This is not a caption",
)


Expand Down
47 changes: 0 additions & 47 deletions greeking/placeholdit.py

This file was deleted.

88 changes: 1 addition & 87 deletions greeking/templatetags/greeking_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from greeking.fillmurray import get_url as get_fillmurray_url
from greeking.jabberwocky import get_grafs
from greeking.jabberwocky import get_html as get_jabberwocky_html
from greeking.latimes_ipsum import get_image, get_quote, get_related_items, get_story
from greeking.latimes_ipsum import get_quote, get_story
from greeking.pangrams import get_html as get_pangram_html
from greeking.pangrams import get_pangram
from greeking.placeholdit import get_url as get_placeholdit_url
from greeking.placekittens import get_url as get_placekitten_url

register = template.Library()
Expand All @@ -32,28 +31,6 @@ def latimes_story():
return get_story()


@register.simple_tag
def latimes_image(width, height, background_color):
"""
Return an latimes_ipsum Image object with a default background color of #ccc unless you specify
a background color. Also has option to return caption and credit.
Usage format:
{% latimes_image [width] [height] [background_color] as obj %}
Example usage:
Image at 250 wide and 400 high with background color of #000
{% latimes_image 250 400 000000 %}
<img src="{{obj.url}}">
{{ obj.caption }}
{{ obj.credit }}
"""
return get_image(width, height, background_color)


@register.simple_tag
def latimes_quote():
"""
Expand All @@ -69,29 +46,6 @@ def latimes_quote():
return get_quote()


@register.simple_tag
def latimes_related_items(count=4):
"""
Return a list of latimes_ipsum Quote object.
Example usage:
{% latimes_related_items as related_items %}
{% for item in related_items %}
<div>
<a href="{{ item.url }}">
<p>{{ item.headline }}</p>
</a>
<a href="{{ item.url }}">
<img src="{{ item.image_url }}">
</a>
</div>
{% endfor %}
"""
return get_related_items(count)


@register.simple_tag
def fillmurray(width, height):
"""
Expand All @@ -110,46 +64,6 @@ def fillmurray(width, height):
return format_html('<img src="{}"/>', url)


@register.simple_tag
def placeholdit(
width,
height,
background_color="cccccc",
text_color="969696",
text=None,
random_background_color=False,
):
"""
Creates a placeholder image using placehold.it
Usage format:
{% placeholdit [width] [height] [background_color] [text_color] [text] %}
Example usage:
Default image at 250 square
{% placeholdit 250 %}
100 wide and 200 high
{% placeholdit 100 200 %}
Custom background and text colors
{% placeholdit 100 200 background_color='fff' text_color=000' %}
Custom text
{% placeholdit 100 200 text='Hello LA' %}
"""
url = get_placeholdit_url(
width,
height,
background_color=background_color,
text_color=text_color,
text=text,
)
return format_html('<img src="{}"/>', url)


@register.simple_tag
def placekitten(width, height):
"""
Expand Down

0 comments on commit 95aa32e

Please sign in to comment.