https://github.com/timnew/lonely-planet
https://github.com/timnew/lonely-planet
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/timnew/lonely-planet
- Owner: timnew
- License: mit
- Created: 2014-07-20T17:26:27.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-07-25T14:42:18.000Z (almost 12 years ago)
- Last Synced: 2025-02-28T18:01:16.404Z (over 1 year ago)
- Language: Ruby
- Homepage: https://github.com/timnew/lonely-planet
- Size: 1.77 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
lonely-planet
==============
[](https://drone.io/github.com/timnew/lonely-planet/latest)
Environment
-----------
The project is written in Ruby 2.0. A `.ruby-version` file is provided, which could be recognized by latest `RVM` or `rbenv`.
Gems are managed by `Bundler`, `Gemfile` and `Gemfile.lock` are provided. `Gemset` is not used.
Quick Start
------------
After checked out or downloaded the source code, execute following command to setup environment and verify whether it works:
```
$ bundle install
$ rake
```
Builder
-----------
`builder` is the main entrance to the app, all the functions can be accessed via this cli tool.
`builder` provides a self contained document, execute:
```
$ ./builder
```
or
```
$ ./builder help
```
will display the document.
#### Build Pages
To render the pages, execute:
```
$ ./builder render
```
A `output` folder will be created under current working directory, which contains all the generated files with all dependent resources, such `css` or `js` files.
** HINT ** For given `taxonomy.xml` and `destinations.xml`, the root page of generated site will be `output/Africa/index.html`
`builder render` provides some options to configure the render process, to know more execute:
```
$ ./builder render --help
```
#### Analyze Destination Semantic Structure
Builder also provide a tool to analyze the xml semantic structure. It list the xml schema tree, min occurrence and max occurrence of each node under a same parent, and the the occurrence of the node across the whole file (weight).
To analyze the `destinations.xml`, execute
```
$ ./builder analyze
```
For more details, execute:
```
$ ./builder analyze --help
```
Here is the schema tree for `destinations.xml` generated by the tool:
```
[0:0] (0)
destinations[0:1] (1)
destination[24:24] (24)
history[0:1] (5)
history[1:1] (5)
history[3:15] (38)
overview[1:1] (5)
introductory[1:1] (24)
introduction[1:1] (24)
overview[1:1] (24)
practical_information[0:1] (8)
health_and_safety[0:1] (7)
before_you_go[0:8] (8)
dangers_and_annoyances[0:4] (9)
in_transit[0:2] (2)
while_youre_there[0:5] (11)
money_and_costs[1:1] (8)
costs[0:1] (2)
money[1:5] (15)
visas[0:1] (5)
overview[0:1] (4)
other[0:4] (6)
permits[0:1] (1)
transport[0:1] (14)
getting_around[0:1] (8)
air[0:2] (4)
bicycle[0:1] (1)
boat[0:1] (1)
car_and_motorcycle[0:3] (5)
hitching[0:1] (2)
local_transport[0:2] (4)
overview[0:1] (5)
train[0:1] (2)
bus_and_tram[0:2] (3)
getting_there_and_away[0:1] (11)
air[0:7] (11)
overview[0:1] (6)
land[0:6] (6)
bus_and_tram[0:3] (5)
getting_there_and_around[0:1] (3)
air[0:3] (3)
bicycle[0:1] (1)
bus_and_tram[0:1] (1)
car_and_motorcycle[0:4] (4)
local_transport[0:2] (2)
overview[1:1] (3)
train[0:1] (1)
weather[0:1] (5)
when_to_go[1:1] (5)
climate[1:2] (6)
overview[0:1] (1)
work_live_study[0:1] (3)
work[1:1] (3)
business[1:1] (3)
overview[0:1] (2)
wildlife[0:1] (1)
animals[1:1] (1)
mammals[1:1] (1)
birds[1:1] (1)
overview[1:1] (1)
endangered_species[1:1] (1)
overview[1:1] (1)
overview[1:1] (1)
overview[1:1] (1)
plants[1:1] (1)
overview[1:1] (1)
```
**HINT:**
* the indention indicates the depth of the node
* [x:y] indicates the min occurrence and max occurrence of the node
* (w) indicates the weight of the node (How many times it occurs across the file)
Rake Tasks
-----------
`Rake` tasks is provided to developer on some development cases.
To know more details, execute:
```
$ rake -T
```
### Tests
To run all the tests, execute:
```
$ rake
```
or
```
$ rake spec
```
### Console
To start a console with all environment loaded, execute:
```
$ rake pry
```
Design
------
* Xml files are parsed into `models`.
* `Actors` consumes the `models` and `view models` and generate pages.
* `View models` provide an abstraction layer beyond the `html`, it describe the page in a specific `DSL`.
* `Templates` provide the `haml template` and `static assets` for the pages
### Taxonomy Nodes
Taxonomy tree is represented by `Taxonomy` and `TaxonomyNode` tree.
### Destinations
Destinations are loaded into `Destination` and `DestinationNode` tree.
To avoid `out of memory` exception when processing large `destinations.xml` file, the data is loaded in SAX way. **Only** the data is under processing is stored in memory, and will be dropped after processed. Besides **only** the destination described in `taxonomy.xml` is loaded and processed.
### Page
`Page` contains `navigation items` and `sections`.
#### Navigation Items
`Navigation Items` is built from `taxonomy tree`. It contains it self, the region it belongs to, the territories it includes.
#### Sections
`Sections` are the main information displayed on the page, each section is represented in a box.
Each `section` contains a `title` and a bunch of `blocks`.
#### Blocks
`Block` is a group of paragraphs in a `section`, it might or might not have title.
A `paragraph limit` can be set to `block`. And the paragraphs beyond the `limit` will be hidden in a collapsable region by default. If user is interested, the can expand the region by click the link to expand the region.
Known Issues
------------
1. The app might nor work properly on Windows
2. The generated pages might not work after moved into another folder, because they locate the javascript, css and other related resources via absolute path.
3. No build script is provided for coffee-scripts
Performance
------------
Run the app 100 times against sample data
### Render Comparison
| Render | user | system | total ( real ) |
|--------------------|-----------------|----------------|-----------------------------------|
| Render Haml | 10.950000 | 0.780000 | 11.730000 ( 11.994275) |
| Render Static | 3.380000 | 1.040000 | 4.420000 ( 5.585403) |
### Method Profiler
#### PageMaker
| Method | Min Time | Max Time | Average Time | Total Time | Total Calls |
|------------------|------------|------------|--------------|--------------|-------------|
| #run | 163.107 ms | 224.110 ms | 183.969 ms | 18396.929 ms | 100 |
| #new_destination | 4.042 ms | 37.823 ms | 6.213 ms | 14910.753 ms | 2400 |
| #load_taxonomy | 1.558 ms | 8.989 ms | 1.781 ms | 178.078 ms | 100 |
| #include? | 0.225 ms | 32.695 ms | 0.327 ms | 783.763 ms | 2400 |
| #log | 0.134 ms | 32.595 ms | 0.194 ms | 991.195 ms | 5100 |
| #initialize | 0.005 ms | 0.016 ms | 0.007 ms | 0.671 ms | 100 |
| #render | 0.003 ms | 0.117 ms | 0.004 ms | 9.861 ms | 2400 |
| #root_path | 0.003 ms | 0.029 ms | 0.004 ms | 9.536 ms | 2400 |
| #taxonomy_nodes | 0.002 ms | 0.023 ms | 0.004 ms | 18.589 ms | 4900 |
#### HamlRender
| Method | Min Time | Max Time | Average Time | Total Time | Total Calls |
|----------------|----------|-----------|--------------|--------------|-------------|
| #initialize | 5.762 ms | 5.762 ms | 5.762 ms | 5.762 ms | 1 |
| #render | 3.406 ms | 37.100 ms | 5.410 ms | 12985.072 ms | 2400 |
| #ensure_folder | 0.135 ms | 23.753 ms | 0.213 ms | 512.392 ms | 2400 |
#### Haml::Engine
| Method | Min Time | Max Time | Average Time | Total Time | Total Calls |
|----------------------|----------|-----------|--------------|--------------|-------------|
| #initialize | 5.615 ms | 5.615 ms | 5.615 ms | 5.615 ms | 1 |
| #render | 2.927 ms | 36.088 ms | 4.695 ms | 11268.170 ms | 2400 |
| #set_locals | 0.028 ms | 28.520 ms | 0.066 ms | 157.806 ms | 2400 |
| #initialize_encoding | 0.009 ms | 0.009 ms | 0.009 ms | 0.009 ms | 1 |
#### File
| Method | Min Time | Max Time | Average Time | Total Time | Total Calls |
|--------------|----------|-----------|--------------|------------|-------------|
| .unlink | 0.027 ms | 4.140 ms | 0.047 ms | 163.014 ms | 3500 |
| #initialize | 0.015 ms | 0.484 ms | 0.034 ms | 82.476 ms | 2400 |
| .exist? | 0.006 ms | 23.463 ms | 0.031 ms | 77.496 ms | 2500 |
| .identical? | 0.010 ms | 0.022 ms | 0.012 ms | 1.213 ms | 100 |
| .directory? | 0.006 ms | 0.041 ms | 0.011 ms | 8.896 ms | 835 |
| .lstat | 0.007 ms | 0.091 ms | 0.010 ms | 72.412 ms | 7200 |
| .file? | 0.006 ms | 0.045 ms | 0.008 ms | 0.496 ms | 61 |
| .stat | 0.006 ms | 0.021 ms | 0.008 ms | 1.599 ms | 200 |
| .join | 0.004 ms | 25.241 ms | 0.008 ms | 263.356 ms | 34097 |
| .expand_path | 0.005 ms | 0.016 ms | 0.007 ms | 0.136 ms | 20 |
| .basename | 0.005 ms | 0.016 ms | 0.006 ms | 0.631 ms | 100 |
| .dirname | 0.003 ms | 0.022 ms | 0.006 ms | 17.213 ms | 3100 |
| .path | 0.003 ms | 0.043 ms | 0.004 ms | 18.439 ms | 4600 |
#### IO
| Method | Min Time | Max Time | Average Time | Total Time | Total Calls |
|---------------|----------|-----------|--------------|-------------|-------------|
| .open | 0.062 ms | 25.703 ms | 0.437 ms | 1049.736 ms | 2400 |
| .write | 0.090 ms | 23.158 ms | 0.188 ms | 451.621 ms | 2400 |
| #puts | 0.094 ms | 32.508 ms | 0.148 ms | 757.768 ms | 5104 |
| .copy_stream | 0.022 ms | 0.502 ms | 0.082 ms | 90.139 ms | 1100 |
| .read | 0.038 ms | 0.038 ms | 0.038 ms | 0.038 ms | 1 |
| #read | 0.007 ms | 25.138 ms | 0.038 ms | 242.239 ms | 6400 |
| #close | 0.009 ms | 0.172 ms | 0.031 ms | 67.169 ms | 2200 |
| #write | 0.006 ms | 6.106 ms | 0.011 ms | 110.723 ms | 10208 |
| #set_encoding | 0.004 ms | 0.008 ms | 0.006 ms | 0.120 ms | 20 |
| #stat | 0.004 ms | 0.024 ms | 0.005 ms | 6.010 ms | 1100 |
#### Page
| Method | Min Time | Max Time | Average Time | Total Time | Total Calls |
|-------------------|----------|-----------|--------------|-------------|-------------|
| #navigation_items | 0.273 ms | 27.499 ms | 0.660 ms | 1583.243 ms | 2400 |
| #sections | 0.004 ms | 28.820 ms | 0.633 ms | 3039.570 ms | 4800 |
| #file_path | 0.004 ms | 24.586 ms | 0.138 ms | 663.585 ms | 4800 |
| #path_for_node | 0.086 ms | 26.777 ms | 0.113 ms | 1138.156 ms | 10100 |
| #title | 0.048 ms | 23.839 ms | 0.085 ms | 203.965 ms | 2400 |
| #section | 0.042 ms | 23.934 ms | 0.063 ms | 1653.213 ms | 26400 |
| #initialize | 0.004 ms | 0.024 ms | 0.006 ms | 13.883 ms | 2400 |
| #root_path | 0.002 ms | 0.119 ms | 0.004 ms | 98.715 ms | 26900 |
| #taxonomy_node | 0.002 ms | 0.122 ms | 0.004 ms | 43.235 ms | 12000 |
| #destination | 0.002 ms | 0.120 ms | 0.003 ms | 81.685 ms | 26400 |