Making WordPress.org

Changeset 676


Ignore:
Timestamp:
06/05/2014 09:42:29 PM (10 years ago)
Author:
coffee2code
Message:

Code Reference: Add inline source code display for functions and methods. props atimmer. See #176

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference.php

    r657 r676  
    117117    endif; ?>
    118118
     119    <?php if ( 'wp-parser-function' === get_post_type() || 'wp-parser-method' === get_post_type() ) : ?>
     120        <hr />
     121        <section class="source-content">
     122            <h2><?php _e( 'Source', 'wporg' ); ?></h2>
     123            <div class="source-code-container">
     124                <pre class="brush: php; toolbar: false;"><?php echo esc_html( get_source_code() ); ?></pre>
     125            </div>
     126            <p><a href="#" class="show-complete-source"><?php _e( 'View full source code&hellip;', 'wporg-developer' ); ?></a></p>
     127        </section>
     128    <?php endif; ?>
     129
    119130<?php endif; ?>
    120131
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php

    r616 r676  
    343343    wp_enqueue_script( 'wporg-developer-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
    344344    wp_enqueue_script( 'wporg-developer-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
     345
     346    if ( 'wp-parser-function' === get_post_type() || 'wp-parser-method' === get_post_type() ) {
     347        wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery', 'syntaxhighlighter-core', 'syntaxhighlighter-brush-php' ), '20140515', true );
     348        wp_enqueue_style( 'syntaxhighlighter-core' );
     349        wp_enqueue_style( 'syntaxhighlighter-theme-default' );
     350    }
     351
    345352    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    346353        wp_enqueue_script( 'comment-reply' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r640 r676  
    639639    }
    640640
     641    /**
     642     * Retrieve source code for a function
     643     *
     644     * @param int $post_id
     645     *
     646     * @return string The sourc
     647     */
     648    function get_source_code( $post_id = null ) {
     649
     650        if ( empty( $post_id ) ) {
     651            $post_id = get_the_ID();
     652        }
     653
     654        // Get the total file sourcecode.
     655        $source_file = get_source_file( $post_id );
     656
     657        // Put the total source code in an array.
     658        $total_source_code = file_get_contents( ABSPATH . $source_file );
     659        $total_source_code = explode( "\n", $total_source_code );
     660
     661        // Get the start and end lines.
     662        $start_line = get_post_meta( $post_id, '_wp-parser_line_num', true ) - 1;
     663        $end_line =   get_post_meta( $post_id, '_wp-parser_end_line_num', true );
     664
     665        // Get the correct source code.
     666        $source_code = array_slice( $total_source_code, $start_line, $end_line - $start_line );
     667
     668        return implode( "\n", $source_code );
     669    }
     670
    641671}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss

    r637 r676  
    855855        }
    856856    }
     857
     858    .source-code-container {
     859        overflow: hidden;
     860    }
     861
     862    .show-complete-source {
     863        display: none;
     864    }
     865
    857866    .loop-pagination {
    858867        text-align: center;
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css

    r637 r676  
    10681068  padding: 20px;
    10691069}
     1070.devhub-wrap .source-code-container {
     1071  overflow: hidden;
     1072}
     1073.devhub-wrap .show-complete-source {
     1074  display: none;
     1075}
    10701076.devhub-wrap .loop-pagination {
    10711077  text-align: center;
Note: See TracChangeset for help on using the changeset viewer.