-
-
Save sumitk/7048704 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name = My module | |
| description = TODO: Description of module | |
| core = 7.x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Renders the weather status for a city. | |
| */ | |
| var app = angular.module('myapp', []) | |
| .controller('MyModuleWeather', function($scope, $http) { | |
| $http.jsonp('http://api.openweathermap.org/data/2.5/weather?q=London,uk&callback=JSON_CALLBACK'). | |
| success(function(data, status, headers, config) { | |
| $scope.main = data.main; | |
| $scope.wind = data.wind; | |
| $scope.description = data.weather[0].description; | |
| }). | |
| error(function(data, status, headers, config) { | |
| // Fail silently. | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @file mymodule.module | |
| * Spike solution to implement an AngularJS-driven block. | |
| */ | |
| /** | |
| * Implements hook_block_info(). | |
| */ | |
| function mymodule_block_info() { | |
| $blocks['weather'] = array( | |
| 'info' => t('Weather'), | |
| ); | |
| return $blocks; | |
| } | |
| /** | |
| * Implements hook_block_view(). | |
| */ | |
| function mymodule_block_view($delta = '') { | |
| $block = array(); | |
| switch ($delta) { | |
| case 'weather': | |
| $path = drupal_get_path('module', 'mymodule'); | |
| $block['subject'] = t('Weater status'); | |
| $block['content'] = array( | |
| '#markup' => theme('weather_status'), | |
| '#attached' => array( | |
| 'js' => array( | |
| 'https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js', | |
| $path . '/mymodule.js', | |
| ), | |
| ), | |
| ); | |
| break; | |
| } | |
| return $block; | |
| } | |
| /** | |
| * Implements hook_theme(). | |
| */ | |
| function mymodule_theme() { | |
| return array( | |
| 'weather_status' => array( | |
| 'template' => 'weather-status', | |
| ), | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @file | |
| * AngularJS template to render a weather block. | |
| */ | |
| ?> | |
| <div ng-controller="MyModuleWeather"> | |
| <h3>{{data.name}}</h3> | |
| <p>{{description}}</p> | |
| <p>Temperature: {{main.temp}}</p> | |
| <p>Wind speed: {{wind.speed}}</p> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment