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

Add support for --ratio-delimter option. Fixes #202 #204

Open
wants to merge 1 commit 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
5 changes: 3 additions & 2 deletions glue/formats/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def output_filename(self, ratio=None, *args, **kwargs):
if self.build_per_ratio:
if ratio is None:
raise AttributeError("Format {0} output_filename requires a ratio.".format(self.__class__))
ratio_suffix = '@%.1fx' % ratio if int(ratio) != ratio else '@%ix' % ratio
if ratio_suffix == '@1x':
delimiter = self.sprite.config.get('ratio_delimiter')
ratio_suffix = delimiter + '%.1fx' % ratio if int(ratio) != ratio else delimiter + '%ix' % ratio
if ratio_suffix == delimiter + '1x':
ratio_suffix = ''
return '{0}{1}'.format(self.sprite.name, ratio_suffix)
return self.sprite.name
Expand Down
6 changes: 6 additions & 0 deletions glue/formats/img.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def populate_argument_parser(cls, parser):
const='2,1',
help="Shortcut for --ratios=2,1")

group.add_argument("--ratio-delimiter",
dest="ratio_delimiter",
type=unicode,
default="@",
help="Ratio symbol delimiter")

def output_filename(self, *args, **kwargs):
filename = super(ImageFormat, self).output_filename(*args, **kwargs)
if self.sprite.config['css_cachebuster_filename'] or self.sprite.config['css_cachebuster_only_sprites']:
Expand Down
47 changes: 47 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1801,5 +1801,52 @@ def test_caat_ratios(self):
data = json.loads(f.read())
assert isinstance(data['sprites'], dict)


def test_delimiter(self):
self.create_image("simple/red.png", RED)
self.create_image("simple/blue.png", BLUE)

# Custom ratio delimiter
code = self.call('glue simple output --retina --ratio-delimiter=-')
self.assertEqual(code, 0)

self.assertExists("output/simple.png")
self.assertExists("output/simple-2x.png")
self.assertExists("output/simple.css")

self.assertCSS(u"output/simple.css", u'.sprite-simple-red',
{u'background-image': u"url(simple.png)",
u'background-repeat': u'no-repeat',
u'background-position': u'0 0',
u'width': u'32px',
u'height': u'32px'})

self.assertCSS(u"output/simple.css", u'.sprite-simple-blue',
{u'background-image': u"url(simple.png)",
u'background-repeat': u'no-repeat',
u'background-position': u'-32px 0',
u'width': u'32px',
u'height': u'32px'})

self.assertCSS(u"output/simple.css", u'.sprite-simple-red',
{u'background-image': u"url(simple-2x.png)",
u'background-repeat': u'no-repeat',
u'background-position': u'0 0',
u'background-size': u'64px 32px',
u'-webkit-background-size': u'64px 32px',
u'-moz-background-size': u'64px 32px',
u'width': u'32px',
u'height': u'32px'}, ratio=2)

self.assertCSS(u"output/simple.css", u'.sprite-simple-blue',
{u'background-image': u"url(simple-2x.png)",
u'background-repeat': u'no-repeat',
u'background-position': u'-32px 0',
u'background-size': u'64px 32px',
u'-webkit-background-size': u'64px 32px',
u'-moz-background-size': u'64px 32px',
u'width': u'32px',
u'height': u'32px'}, ratio=2)

if __name__ == '__main__':
unittest.main()