Skip to content

Instantly share code, notes, and snippets.

@sumitk
Forked from juampynr/html.tpl.php
Created October 18, 2013 21:45
Show Gist options
  • Save sumitk/7048704 to your computer and use it in GitHub Desktop.
Save sumitk/7048704 to your computer and use it in GitHub Desktop.

Revisions

  1. Juan Pablo Novillo revised this gist Oct 17, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mymodule.module
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ function mymodule_block_view($delta = '') {
    switch ($delta) {
    case 'weather':
    $path = drupal_get_path('module', 'mymodule');
    $block['subject'] = t('Weater status');
    $block['subject'] = t('Weather status');
    $block['content'] = array(
    '#markup' => theme('weather_status'),
    '#attached' => array(
  2. @juampynr juampynr revised this gist Aug 19, 2013. 1 changed file with 63 additions and 0 deletions.
    63 changes: 63 additions & 0 deletions html.tpl.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    <?php

    /**
    * @file
    * Default theme implementation to display the basic html structure of a single
    * Drupal page.
    *
    * Variables:
    * - $css: An array of CSS files for the current page.
    * - $language: (object) The language the site is being displayed in.
    * $language->language contains its textual representation.
    * $language->dir contains the language direction. It will either be 'ltr' or 'rtl'.
    * - $rdf_namespaces: All the RDF namespace prefixes used in the HTML document.
    * - $grddl_profile: A GRDDL profile allowing agents to extract the RDF data.
    * - $head_title: A modified version of the page title, for use in the TITLE
    * tag.
    * - $head_title_array: (array) An associative array containing the string parts
    * that were used to generate the $head_title variable, already prepared to be
    * output as TITLE tag. The key/value pairs may contain one or more of the
    * following, depending on conditions:
    * - title: The title of the current page, if any.
    * - name: The name of the site.
    * - slogan: The slogan of the site, if any, and if there is no title.
    * - $head: Markup for the HEAD section (including meta tags, keyword tags, and
    * so on).
    * - $styles: Style tags necessary to import all CSS files for the page.
    * - $scripts: Script tags necessary to load the JavaScript files and settings
    * for the page.
    * - $page_top: Initial markup from any modules that have altered the
    * page. This variable should always be output first, before all other dynamic
    * content.
    * - $page: The rendered page content.
    * - $page_bottom: Final closing markup from any modules that have altered the
    * page. This variable should always be output last, after all other dynamic
    * content.
    * - $classes String of classes that can be used to style contextually through
    * CSS.
    *
    * @see template_preprocess()
    * @see template_preprocess_html()
    * @see template_process()
    *
    * @ingroup themeable
    */
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
    "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
    <html data-ng-app="myapp" xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>"<?php print $rdf_namespaces; ?>>

    <head profile="<?php print $grddl_profile; ?>">
    <?php print $head; ?>
    <title><?php print $head_title; ?></title>
    <?php print $styles; ?>
    <?php print $scripts; ?>
    </head>
    <body class="<?php print $classes; ?>" <?php print $attributes;?>>
    <div id="skip-link">
    <a href="#main-content" class="element-invisible element-focusable"><?php print t('Skip to main content'); ?></a>
    </div>
    <?php print $page_top; ?>
    <?php print $page; ?>
    <?php print $page_bottom; ?>
    </body>
    </html>
  3. @juampynr juampynr revised this gist Aug 12, 2013. 3 changed files with 36 additions and 15 deletions.
    38 changes: 27 additions & 11 deletions mymodule.js
    Original file line number Diff line number Diff line change
    @@ -3,15 +3,31 @@
    */
    var app = angular.module('myapp', [])
    .controller('MyModuleWeather', function($scope, $http, $log) {
    // Fetch the data from the public API through JSONP.
    var url = 'http://api.openweathermap.org/data/2.5/weather?q=London,uk&callback=JSON_CALLBACK';
    $http.jsonp(url).
    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) {
    $log.error('Could not retrieve data from ' + url);
    });
    // Set default values for our form fields.
    $scope.city = 'Madrid';
    $scope.units = 'metric';

    // Define a function to process form submission.
    $scope.change = function() {
    // Fetch the data from the public API through JSONP.
    // See http://openweathermap.org/API#weather.
    var url = 'http://api.openweathermap.org/data/2.5/weather';
    $http.jsonp(url, { params : {
    q : $scope.city,
    units : $scope.units,
    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) {
    // Log an error in the browser's console.
    $log.error('Could not retrieve data from ' + url);
    });
    };

    // Trigger form submission for first load.
    $scope.change();
    });
    4 changes: 2 additions & 2 deletions mymodule.module
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    /**
    * @file mymodule.module
    *
    * Spike solution to implement an AngularJS-driven block.
    * Implements an AngularJS-driven block.
    */

    /**
    @@ -49,4 +49,4 @@ function mymodule_theme() {
    'template' => 'weather-status',
    ),
    );
    }
    }
    9 changes: 7 additions & 2 deletions weather-status.tpl.php
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,18 @@
    <?php
    /**
    * @file
    *
    * AngularJS template to render a weather block.
    */
    ?>
    <div ng-controller="MyModuleWeather">
    <label for="city">City</label>
    <input type="text" ng-model="city" /></br>
    <label for="units">Units</label>
    <input type="radio" ng-model="units" value="metric"/> Metric
    <input type="radio" ng-model="units" value="imperial"/> Imperial</br>
    <button ng-click="change()">Change</button>
    <h3>{{data.name}}</h3>
    <p>{{description}}</p>
    <p>Temperature: {{main.temp}}</p>
    <p>Wind speed: {{wind.speed}}</p>
    </div>
    </div>
  4. @juampynr juampynr revised this gist Jul 15, 2013. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions mymodule.js
    Original file line number Diff line number Diff line change
    @@ -2,15 +2,16 @@
    * 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').
    .controller('MyModuleWeather', function($scope, $http, $log) {
    // Fetch the data from the public API through JSONP.
    var url = 'http://api.openweathermap.org/data/2.5/weather?q=London,uk&callback=JSON_CALLBACK';
    $http.jsonp(url).
    success(function(data, status, headers, config) {
    // The scope variable is like the $variables array in Drupal's theming system.
    $scope.main = data.main;
    $scope.wind = data.wind;
    $scope.description = data.weather[0].description;
    }).
    error(function(data, status, headers, config) {
    // Fail silently.
    $log.error('Could not retrieve data from ' + url);
    });
    });
    });
  5. @juampynr juampynr revised this gist Jul 15, 2013. 2 changed files with 2 additions and 0 deletions.
    1 change: 1 addition & 0 deletions mymodule.module
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    <?php
    /**
    * @file mymodule.module
    *
    * Spike solution to implement an AngularJS-driven block.
    */

    1 change: 1 addition & 0 deletions weather-status.tpl.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    <?php
    /**
    * @file
    *
    * AngularJS template to render a weather block.
    */
    ?>
  6. @juampynr juampynr revised this gist Jul 15, 2013. 2 changed files with 2 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion mymodule.info
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    name = My module
    description = TODO: Description of module
    description = Implements an AngularJS-driven block
    core = 7.x
    1 change: 1 addition & 0 deletions mymodule.js
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@ 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) {
    // The scope variable is like the $variables array in Drupal's theming system.
    $scope.main = data.main;
    $scope.wind = data.wind;
    $scope.description = data.weather[0].description;
  7. @juampynr juampynr created this gist Jul 15, 2013.
    3 changes: 3 additions & 0 deletions mymodule.info
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    name = My module
    description = TODO: Description of module
    core = 7.x
    15 changes: 15 additions & 0 deletions mymodule.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    /**
    * 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.
    });
    });
    51 changes: 51 additions & 0 deletions mymodule.module
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    <?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',
    ),
    );
    }
    12 changes: 12 additions & 0 deletions weather-status.tpl.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <?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>