Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alct committed Aug 18, 2015
0 parents commit d497728
Show file tree
Hide file tree
Showing 13 changed files with 1,855 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin/bookmarklet_*_*.js
lib/composer
lib/spotch
22 changes: 22 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Non-exhaustive list of people who contributed to this project.

Name (N), email (E), web-address (W), description (D).

---

N: Michaël Lecerf
E: michael@nurpa.be
D: Contributed to the JS code

N: André Loconte
E: andre@nurpa.be
D: Original dev

N: Laurent Peuch
E: laurent@nurpa.be
D: Contributed to the Bash code

N: Wim Vandenbussche
E: wim@datapanik.org
W: http://datapanik.org
D: Dutch translation
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Better Lex bookmarklet

Better Lex bookmarklet is a tool for improving readability of the online Belgian consolidated legislation. It requires a modern Web browser, such as Firefox.

## Overview

Here is the structure of this project.

```
betterlex-bookmarklet
├── bin
│   ├── bookmarklet_fr.js
│   └── bookmarklet_nl.js
├── lib
├── scripts
│   ├── build
│   └── install
├── src
│   ├── main.css
│   ├── main.js
│   ├── translations.json
│   └── utility.js
├── CREDITS
├── LICENSE
└── README.md
```

## How to build the bookmarklet from scratch

### Dependencies

* PHP 5.4 or any newer version
* [Composer](https://getcomposer.org/), a package manager for PHP
* [spotch](https://github.com/miclf/spotch), a bookmarklet generator

### Download and install dependencies

You can use the following bash script to install the project’s dependencies.

```bash
./scripts/install
```

### Build the bookmarklet

Once the dependencies are installed, you just need to run this build script to generate both the French and Dutch versions of the bookmarklet.

```bash
./scripts/build
```

## License

This is free/libre software, made available under the terms of the [GNU General Public License (GPLv3)](LICENSE).
1 change: 1 addition & 0 deletions bin/bookmarklet_fr.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bin/bookmarklet_nl.js

Large diffs are not rendered by default.

Empty file added lib/.placeholder
Empty file.
57 changes: 57 additions & 0 deletions scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash


# Execute the script from the right location

source="${BASH_SOURCE}"

while [ -h "$source" ]; do
source="$(readlink $source)"
done

cd "$(dirname $source)"


# Resources

bin="../bin/"
src="../src/"

css="${src}main.css"
main="${src}main.js"
trans="${src}translations.json"
utils="${src}utility.js"


# Where the magic happens

for bookmarkletLang in "nl" "fr"; do

tmpCSS=$(mktemp -t "blex_css.js.XXXXXXXXXX")
tmpTrans=$(mktemp -t "blex_trans.js.XXXXXXXXXX")
timestamp=$(date +"%Y-%m-%d_%Hh%M")

## Generate temporary files containing JS vars

### CSS (minified)

if [ -f "$tmpCSS" ]; then
echo "var css = '$(cat $css)';" > "$tmpCSS"
else
echo "betterlex: unable to create temporary file $tmpCSS"
exit
fi

### Translations

if [ -f "$tmpTrans" ]; then
echo "var bookmarkletLang = '$bookmarkletLang'; window._translations = $(cat $trans);" > "$tmpTrans"
else
echo "betterlex: unable to create temporary file $tmpTrans"
exit
fi

## Generate the bookmarklet

../lib/spotch/bin/spotch make "$tmpTrans" "$tmpCSS" "$utils" "$main" --output "${bin}bookmarklet_${bookmarkletLang}_${timestamp}.js" --no-minify "$tmpTrans"
done
69 changes: 69 additions & 0 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash


# Execute the script from the right location

source="${BASH_SOURCE}"

while [ -h "$source" ]; do
source="$(readlink $source)"
done

cd "$(dirname $source)"


# Utility functions

function is_installed()
{
command -v "$1" >/dev/null 2>&1
}

function status()
{
echo
echo "betterlex: $1"
echo
}


# Move to the "lib" directory

cd ../lib


# Create directories

for dir in "composer" "spotch"; do
if [ ! -d "$dir" ]; then
mkdir "$dir"
fi
done


# Install dependencies

## Check if PHP is installed

if ! is_installed php; then
status "please install PHP before continuing."
exit
fi

## Install Composer

if [ ! -e "composer/composer.phar" ]; then
status "installing Composer..."

php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=composer
fi

## Install Spotch

if [ ! -e "spotch/bin/spotch" ]; then
status "installing Spotch..."

git clone "https://github.com/miclf/spotch.git" "spotch"
(cd spotch && ../composer/composer.phar update)
chmod +x "spotch/bin/spotch"
fi
Loading

0 comments on commit d497728

Please sign in to comment.