├── web ├── packages ├── hn.html ├── hn.css └── hn.dart ├── README.md ├── pubspec.yaml ├── .gitignore └── LICENSE /web/packages: -------------------------------------------------------------------------------- 1 | ../packages -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | dart-hn 2 | ======= 3 | 4 | A very basic HN client in Dart. 5 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hn 2 | description: A sample web application 3 | dependencies: 4 | browser: any 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Don’t commit the following directories created by pub. 2 | build/ 3 | packages/ 4 | .buildlog 5 | 6 | # Or the files created by dart2js. 7 | *.dart.js 8 | *.dart.precompiled.js 9 | *.js_ 10 | *.js.deps 11 | *.js.map 12 | 13 | # Include when developing application packages. 14 | pubspec.lock 15 | -------------------------------------------------------------------------------- /web/hn.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Hn 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |

HN

16 | 17 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /web/hn.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | background-color: #F8F8F8; 4 | font-family: 'Open Sans', sans-serif; 5 | font-size: 14px; 6 | font-weight: normal; 7 | line-height: 1.2em; 8 | margin: 15px; 9 | } 10 | 11 | h1, p { 12 | color: #333; 13 | } 14 | 15 | #sample_container_id { 16 | width: 100%; 17 | height: 400px; 18 | position: relative; 19 | border: 1px solid #ccc; 20 | background-color: #fff; 21 | } 22 | 23 | #sample_text_id { 24 | font-size: 24pt; 25 | text-align: center; 26 | margin-top: 140px; 27 | -webkit-user-select: none; 28 | user-select: none; 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Karan Goel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /web/hn.dart: -------------------------------------------------------------------------------- 1 | import 'dart:html'; 2 | import 'dart:convert'; 3 | import 'dart:math'; 4 | 5 | const String TOP_STORIES_URL = 'https://hacker-news.firebaseio.com/v0/topstories.json'; 6 | const String STORY_URL = 'https://hacker-news.firebaseio.com/v0/item/ID.json'; 7 | const int MAX_STORIES = 30; 8 | 9 | void main() { 10 | getTopIds(); 11 | } 12 | 13 | void getTopIds() { 14 | HttpRequest.getString(TOP_STORIES_URL).then(getStories); 15 | } 16 | 17 | void getStories(String data) { 18 | List decoded = JSON.decode(data); 19 | List finalObjs = new List(); 20 | 21 | int processed_counter = 0; 22 | int max_items = min(decoded.length, MAX_STORIES); 23 | 24 | for (var i = 0; i < max_items; i++) { 25 | HttpRequest.getString(STORY_URL.replaceFirst('ID', decoded[i].toString())).then((str) { 26 | Map obj = JSON.decode(str); 27 | querySelector('#hn').children.add(new LIElement() 28 | ..append(new AnchorElement() 29 | ..href = obj['url'] 30 | ..text = obj['title'] 31 | ..target = '_blank')); 32 | }); 33 | } 34 | } 35 | --------------------------------------------------------------------------------