Skip to content

Commit

Permalink
More Aggressive Abbreviating, Offset, Center, & Source Ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Rathke committed Dec 10, 2015
1 parent 93bb985 commit ce5025a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
51 changes: 44 additions & 7 deletions library/editor-shortcodes/grid/shortcode-grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,58 @@

function render_foundation_column( $atts, $content = '' ) {

// Normalize Attributes to Identify Unnamed Attributes
$atts = normalize_attributes($atts);

// Declare Acceptable Attributes
$atts = shortcode_atts(array(
'sm-width' => '',
'md-width' => '',
'lg-width' => '',
'sm' => '',
'md' => '',
'lg' => '',
'sm-off' => '',
'md-off' => '',
'lg-off' => '',
'sm-ctr' => 0,
'md-ctr' => 0,
'lg-ctr' => 0,
'sm-pull' => '',
'md-pull' => '',
'lg-pull' => '',
'sm-push' => '',
'md-push' => '',
'lg-push' => '',
), $atts);

$atts['sm-width'] ? $column_classes[] = 'small-' . $atts['sm-width'] : null;
$atts['md-width'] ? $column_classes[] = 'medium-' . $atts['md-width'] : null;
$atts['lg-width'] ? $column_classes[] = 'large-' . $atts['lg-width'] : null;
// Define Column Widths
$atts['sm'] ? $column_classes[] = 'small-' . $atts['sm'] : null;
$atts['md'] ? $column_classes[] = 'medium-' . $atts['md'] : null;
$atts['lg'] ? $column_classes[] = 'large-' . $atts['lg'] : null;

// Define Column Offsets
$atts['sm-off'] ? $column_classes[] = 'small-offset-' . $atts['sm-off'] : null;
$atts['md-off'] ? $column_classes[] = 'medium-offset-' . $atts['md-off'] : null;
$atts['lg-off'] ? $column_classes[] = 'large-offset-' . $atts['lg-off'] : null;

// Define Column Center
$atts['sm-ctr'] ? $column_classes[] = 'small-centered' : null;
$atts['md-ctr'] ? $column_classes[] = 'medium-centered' : null;
$atts['lg-ctr'] ? $column_classes[] = 'large-centered' : null;

// Define Source Odering
$atts['sm-pull'] ? $column_classes[] = 'small-pull-' . $atts['sm-pull'] : null;
$atts['md-pull'] ? $column_classes[] = 'medium-pull-' . $atts['md-pull'] : null;
$atts['lg-pull'] ? $column_classes[] = 'large-pull-' . $atts['lg-pull'] : null;
$atts['sm-push'] ? $column_classes[] = 'small-push-' . $atts['sm-push'] : null;
$atts['md-push'] ? $column_classes[] = 'medium-push-' . $atts['md-push'] : null;
$atts['lg-push'] ? $column_classes[] = 'large-push-' . $atts['lg-push'] : null;


// Turn Column Class Array into String for HTML
$column_class = implode( ' ', $column_classes );

return do_shortcode( "<div class='column {$column_class}'>" . $content . '</div>' );
}
add_shortcode( 'fdn-column', 'render_foundation_column' );
add_shortcode( 'fdn-col', 'render_foundation_column' );

function render_foundation_row( $atts, $content = '' ) {
return do_shortcode( '<div class="row">' . $content . '</div>' );
Expand Down
18 changes: 18 additions & 0 deletions library/editor-shortcodes/shortcodes-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,22 @@

require ( 'grid/shortcode-grid.php' );



/** Normalize Unnamed Attributes
* This function allows us to use unnamed attributes as
* boolean operators by replacing the key of the attribute
* with an identifiable string.
*/
function normalize_attributes($atts) {
foreach ($atts as $key => $value) {
if (is_int($key)) {
$atts[$value] = true;
unset($atts[$key]);
}
}

return $atts;
}

?>

1 comment on commit ce5025a

@joshrathke
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.