Skip to content

Commit

Permalink
✨ Added rem to pixel conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
KurzGedanke committed Jul 26, 2020
1 parent e3142f7 commit 73577f6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ values.

## Install

**COMING SOON**

```bash
pip install rem-calc
```
Expand All @@ -31,13 +29,20 @@ Commands:
calculate
interactive
```
### Single Value Calculation
### Single Rem Calculation

```bash
$ rem-calc calculate --base 16 --target 20
1.25rem
```

### Single Pixel Calculation

```bash
$ rem-calc inverse --base 16 --rem 2.75
44px
```

### Interactive Value Calculation

```bash
Expand Down
14 changes: 11 additions & 3 deletions rem_calc/rem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def __init__(self, base_size):

def calc_loop(self):
rem_target = ""
while(rem_target != 'n'):
while rem_target != 'n':
rem_target = self.get_px()
self.print_calc(self.calculate(rem_target))

Expand All @@ -13,9 +13,17 @@ def calculate(self, px):

return rem

def calculate_inverse(self, rem):
rem = int((float(rem) * float(self.base_size)))

return rem

@staticmethod
def print_calc(rem):
print(f'{rem}rem')
def print_calc(value, method):
if method == 'rem':
print(f'{value}rem')
elif method == 'px':
print(f'{value}px')

@staticmethod
def get_px():
Expand Down
11 changes: 10 additions & 1 deletion rem_calc/rem_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ def interactive(base):
@click.option('--target', prompt='Enter target pixel', help='REM Pixel Target')
def calculate(base, target):
calc = Calc(base)
calc.print_calc(calc.calculate(target))
calc.print_calc(calc.calculate(target), 'rem')


@click.command()
@click.option('--base', prompt='Enter base pixel', help='REM Pixel Base')
@click.option('--rem', prompt='Enter rem', help='Rem')
def inverse(base, rem):
calc = Calc(base)
calc.print_calc(calc.calculate_inverse(rem), 'px')


main.add_command(interactive)
main.add_command(calculate)
main.add_command(inverse)

if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ def read(fname):

setup(
name='rem-calc',
version='1.0',
version='1.1.0',
author='KurzGedanke',
author_email="rem_calc@kurzgedanke.me",
license='MIT',
keywords='rem css webdev',
description="rem-calc helps you to calculate rem values based on pixel values.",
url='https://github.com/KurzGedanke/rem-calc',
download_url='https://github.com/KurzGedanke/rem-calc/archive/v1.0.0.tar.gz',
download_url='https://github.com/KurzGedanke/rem-calc/archive/v1.1.0.tar.gz',
long_description_content_type='text/markdown',
long_description=read('README.md'),
packages=find_packages(),
Expand Down

0 comments on commit 73577f6

Please sign in to comment.