/**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->package('patricktalmadge/bootstrapper');
        $this->app['config']->package('patricktalmadge/bootstrapper', __DIR__ . '/../config');

        Helpers::setContainer($this->app);
    }
Example #2
0
 /**
  * Checks call to see if we can create a table from a magic call (for you wizards).
  * hover_striped, bordered_condensed, etc.
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return mixed
  */
 public static function __callStatic($method, $parameters)
 {
     $method_array = explode('_', strtolower($method));
     $function = 'table';
     $parameters = Helpers::set_multi_class_attributes($function, $method_array, $parameters, 1, 'table-');
     return call_user_func_array('static::' . $function, $parameters);
 }
Example #3
0
    /**
     * Create a new Navbar instance.
     *
     * @param  string     $brand
     * @param  string     $brand_url
     * @param  array      $menu
     * @param  string     $type
     * @param  bool       $collapsible	
     * @param  array      $attributes 
     * @param  bool  	  $autoroute
     * @return Navbar
     */
    public static function create($brand, $brand_url, $menus, $type = Navbar::STATIC_BAR, $collapsible = false, $attributes = array(), $autoroute = true)
    {
        $attributes = Helpers::add_class($attributes, 'navbar ' . $type);
        //Open navbar containers
        $html = '<div' . HTML::attributes($attributes) . '>';
        $html .= '<div class="navbar-inner"><div class="container">';
        if ($collapsible) {
            $html .= '<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
				        <span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
				    </a>';
        }
        $html .= '<a class="brand" href="' . $brand_url . '">' . $brand . '</a>';
        if ($collapsible) {
            $html .= '<div class="nav-collapse">';
        }
        foreach ($menus as $menu) {
            // If is string add to html
            if (is_string($menu)) {
                $html .= $menu;
            } else {
                $attr = isset($menu['attributes']) ? $menu['attributes'] : array();
                $html .= Navigation::unstyled($menu['items'], false, $attr, $autoroute);
            }
        }
        if ($collapsible) {
            $html .= '</div>';
        }
        //close navbar containers
        $html .= '</div></div></div>';
        return $html;
    }
Example #4
0
 /**
  * Normalizes the items list and correct urls if any are set.
  *
  * @param  array   $items
  * @param  array   $panes
  * @param  int 	   $i
  * @return array
  */
 protected static function normalize($items, &$panes, &$i = 0)
 {
     $id = Helpers::rand_string(5);
     $tabs = array();
     if (!is_array($items)) {
         return;
     }
     foreach ($items as $key => $item) {
         $tab = $item;
         if (isset($tab['items'])) {
             $tab['items'] = static::normalize($tab['items'], $panes, $i);
         } else {
             if (!isset($tab['content'])) {
                 $tab['content'] = '';
             }
             $tabId = 'tab_' . $id . '_' . $i;
             $tab['attributes'] = array('data-toggle' => 'tab');
             $tab['url'] = '#' . $tabId;
             $class = 'tab-pane';
             if (isset($tab['active']) && $tab['active']) {
                 $class .= ' active';
             }
             $panes[] = '<div class="' . $class . '" id="' . $tabId . '">' . $tab['content'] . '</div>';
             unset($tab['content']);
             $i++;
         }
         $tabs[] = $tab;
     }
     return $tabs;
 }
Example #5
0
    public function testOutputCorrectJSLinks()
    {
        $js = Helpers::get_JS();

        $this->assertEquals(
            "<script src='http://code.jquery.com/jquery-2.1.0.min.js'></script><script src='//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js'></script>",
            $js
        );
    }
 /**
  * Opens a new ButtonGroup section.
  *
  * @param string $toggle     Whether the button group should be togglable
  * @param array  $attributes An array of attributes
  *
  * @return string An opening <div> tag
  */
 public static function open($toggle = null, $attributes = array())
 {
     $validToggles = array(ButtonGroup::TOGGLE_CHECKBOX, ButtonGroup::TOGGLE_RADIO);
     if (isset($toggle) && in_array($toggle, $validToggles)) {
         $attributes['data-toggle'] = 'buttons-' . $toggle;
     }
     $attributes = Helpers::add_class($attributes, 'btn-group');
     return '<div' . HTML::attributes($attributes) . '>';
 }
Example #7
0
 /**
  * Create a new Alert.
  *
  * @param  string     $type
  * @param  string     $message
  * @param  bool       $enable_close
  * @param  array      $attributes
  * @return string     Alert HTML
  */
 protected static function show($type, $message, $enable_close = true, $attributes = array())
 {
     $attributes = Helpers::add_class($attributes, 'alert ' . $type);
     $html = '<div' . HTML::attributes($attributes) . '>';
     if ($enable_close) {
         $html .= '<a class="close" data-dismiss="alert" href="#">&times;</a>';
     }
     $html .= $message . '</div>';
     return $html;
 }
Example #8
0
 /**
  * Allows magic methods such as Icons::home([attributes]) or Icons::close_white()
  *
  * @param  string $method
  * @param  array  $attributes
  * @return string
  */
 public static function __callStatic($method, $parameters)
 {
     // Explode method name
     $method = explode('_', strtolower($method));
     // Get icon name
     $method_array = array(array_get($method, 0));
     // Set facultative white flag
     if (array_get($method, sizeof($method) - 1) == 'white') {
         $method_array[] = 'white';
     }
     // Prepend icon- to classes
     $parameters = Helpers::set_multi_class_attributes(null, $method_array, $parameters, 0, 'icon-');
     return '<i' . HTML::attributes($parameters[0]) . '></i>';
 }
 /**
  * Creates a DropdownButton.
  *
  * @param  string  $type
  * @param  string  $value
  * @param  array   $list
  * @param  array   $attributes
  * @param  bool    $right
  * @param  bool    $dropup
  * @param  bool    $autoroute
  * @return string
  */
 protected static function show($type, $value, $list, $attributes = array(), $right = false, $dropup = false, $autoroute = true)
 {
     $attributes = Helpers::add_class($attributes, 'btn-group');
     $list_attr = array();
     if ($right) {
         $list_attr['class'] = 'pull-right';
     }
     if ($dropup) {
         $attributes['class'] .= ' dropup';
     }
     $html = '<div' . HTML::attributes($attributes) . '>';
     $html .= Form::button($value, array('class' => $type), true);
     $html .= Navigation::dropdown($list, $list_attr, $autoroute);
     $html .= '</div>';
     return $html;
 }
Example #10
0
    /**
     * Creates the a new Breadcrumb.
     *
     * @param array $links An array of breadcrumbs links
     * @param array $attributes Attributes to apply the breadcrumbs wrapper
     *
     * @return string A breadcrumbs-styled unordered list
     */
    public static function create($links, $attributes = array())
    {
        // If no links given, cancel
        if (empty($links)) {
            return false;
        }

        // Render each link
        $listItems = array();
        foreach ($links as $label => $url) {
            $listItems[] = (is_string($label) or is_array($url))
                ? static::renderItem(Helpers::getContainer('html')->link($url, $label))
                : static::renderItem($url, true);
        }

        return Lists::ul($listItems, $attributes)->addClass('breadcrumb');
    }
Example #11
0
 /**
  * Allows magic methods such as Icons::home([attributes]) or Icons::close_white()
  * 
  * Sample Usage:
  * <code>
  * <?php
  * Icons::plus();
  * // <i class="icon-plus"></i>
  * Icons::folder_open(array('class'=>'widget','data-foo'=>'bar'));
  * // <i class="widget icon-folder-open" data-foo="bar"></i> 
  * Icons::circle_arrow_right_white();
  * // <i class="icon-circle-arrow-right icon-white"></i>
  * ?>
  * </code>
  *
  * @param  string $method
  * @param  array  $attributes
  * @return string
  */
 public static function __callStatic($method, $attributes)
 {
     // Explode method name
     $method_bits = explode('_', strtolower($method));
     //white icon variant? (when using glyphicons sprite version)
     $white = in_array('white', $method_bits);
     //remove the white!
     $method_bits = array_filter($method_bits, function ($val) {
         return $val != 'white';
     });
     // Get icon name
     $icon_classes = array(implode('-', $method_bits));
     if ($white) {
         $icon_classes[] = 'white';
     }
     // Prepend icon- to classes
     $parameters = Helpers::set_multi_class_attributes(null, $icon_classes, $attributes, 0, 'icon-');
     return '<i' . HTML::attributes($parameters[0]) . '></i>';
 }
 /**
  * Creates the a new Breadcrumb.
  *
  * @param array $links      An array of breadcrumbs links
  * @param array $attributes Attributes to apply the breadcrumbs wrapper
  *
  * @return string A breadcrumbs-styled unordered list
  */
 public static function create($links, $attributes = array())
 {
     // If no links given, cancel
     if (empty($links)) {
         return false;
     }
     // Render each link
     $l = array();
     foreach ($links as $label => $url) {
         $l[] = (is_string($label) or is_array($url)) ? static::renderItem(HTML::link($url, $label)) : static::renderItem($url, true);
     }
     // Add global .breadcrumb class
     $attributes = Helpers::add_class($attributes, 'breadcrumb');
     // Wrap in an <ul> tag
     $html = '<ul' . HTML::attributes($attributes) . '>';
     $html .= implode('', $l);
     $html .= '</ul>';
     return $html;
 }
Example #13
0
 /**
  * Create a Bootstrap carousel. Returns the HTML for the carousel.
  *
  * @param  array   $items
  * @param  array   $attributes
  * @return Carousel
  */
 public static function create($items, $attributes = array())
 {
     $attributes = Helpers::add_class($attributes, 'carousel slide');
     if (!isset($attributes['id'])) {
         $attributes['id'] = "carousel_" . Helpers::rand_string(5);
     }
     $html = '<div' . HTML::attributes($attributes) . '>';
     $html .= '<div class="carousel-inner">';
     $first = true;
     foreach ($items as $item) {
         $html .= static::createItem($item, $first);
         $first = false;
     }
     $html .= '</div>';
     $html .= '<a class="carousel-control left" href="#' . $attributes['id'] . '" data-slide="prev">' . Carousel::$prev . '</a>';
     $html .= '<a class="carousel-control right" href="#' . $attributes['id'] . '" data-slide="next">' . Carousel::$next . '</a>';
     $html .= '</div>';
     return $html;
 }
Example #14
0
 /**
  * Creates the a new Breadcrumb.
  * @param array 	$links
  * @param array 	$attributes
  * @return string
  */
 public static function create($links, $attributes = array())
 {
     if (empty($links)) {
         return;
     }
     $l = array();
     foreach ($links as $label => $url) {
         if (is_string($label) || is_array($url)) {
             $l[] = static::renderItem('<a href="' . $url . '">' . $label . '</a>');
         } else {
             $l[] = static::renderItem($url, true);
         }
     }
     $attributes = Helpers::add_class($attributes, 'breadcrumb');
     $html = '<ul' . HTML::attributes($attributes) . '>';
     $html .= implode('', $l);
     $html .= '</ul>';
     return $html;
 }
Example #15
0
    /**
     * Allows magic methods such as Icon::home([attributes]) or Icon::close_white()
     *
     * Sample Usage:
     * <code>
     * Icon::plus();
     * // <i class="icon-plus"></i>
     * Icon::folder_open(array('class'=>'widget','data-foo'=>'bar'));
     * // <i class="widget icon-folder-open" data-foo="bar"></i>
     * Icon::circle_arrow_right_white();
     * // <i class="icon-circle-arrow-right icon-white"></i>
     * </code>
     *
     * @param string $method     Name of missing method
     * @param array  $parameters array of parameters passed to missing method
     *
     * @return string
     */
    public static function __callStatic($method, $parameters)
    {
        // Explode method name
        $classes = explode('_', strtolower($method));
        $white = in_array('white', $classes);
        if ($white) unset($classes[array_search('white', $classes)]);

      
        // Concatenate icons
        $classes = Helpers::getContainer('config')->get('bootstrapper::icon_prefix') . implode('-', $classes);
        if ($white) $classes .= ' ' .Helpers::getContainer('config')->get('bootstrapper::icon_prefix').'white';
        $classes = Helpers::getContainer('config')->get('bootstrapper::icon_class') . ' ' . $classes;

        $attributes = isset($parameters[0]) ? $parameters[0] : $parameters;

        $icon = new static($attributes);
        $icon->addClass($classes);

        return $icon;
    }
Example #16
0
 /**
  * Allows magic methods such as Icon::home([attributes]) or Icon::close_white()
  *
  * Sample Usage:
  * <code>
  * <?php
  * Icon::plus();
  * // <i class="icon-plus"></i>
  * Icon::folder_open(array('class'=>'widget','data-foo'=>'bar'));
  * // <i class="widget icon-folder-open" data-foo="bar"></i>
  * Icon::circle_arrow_right_white();
  * // <i class="icon-circle-arrow-right icon-white"></i>
  * ?>
  * </code>
  *
  * @param string $method     Name of missing method
  * @param array  $parameters array of parameters passed to missing method
  *
  * @return string
  */
 public static function __callStatic($method, $parameters)
 {
     // Explode method name
     $method_bits = explode('_', strtolower($method));
     // White icon variant? (when using glyphicons sprite version)
     $white = in_array('white', $method_bits);
     // Remove white from array
     $method_bits = array_filter($method_bits, function ($val) {
         return $val != 'white';
     });
     // Get icon name
     $icon_classes = array(implode('-', $method_bits));
     if ($white) {
         $icon_classes[] = 'white';
     }
     // If the parameters weren't put into an array, do it
     if (!isset($parameters[0])) {
         $parameters = array(0 => $parameters);
     }
     // Prepend icon- to classes
     $parameters = Helpers::set_multi_class_attributes(null, $icon_classes, $parameters, 0, Config::get('icons_prefix'));
     return '<i' . HTML::attributes($parameters[0]) . '></i>';
 }
Example #17
0
 /**
  * Create a text box with the search-query class.
  *
  * @see Laravel\Form::text()
  * @param  string  $name
  * @param  string  $value
  * @param  array   $attributes
  * @return string
  */
 public static function search_box($name, $value = null, $attributes = array())
 {
     $attributes = Helpers::add_class($attributes, 'search-query');
     return static::text($name, $value, $attributes);
 }
Example #18
0
    /**
     * Build a range of numeric pagination links.
     *
     * For the current page, an HTML span element will be generated instead of a link.
     *
     * @param int $start starting position
     * @param int $end ending position
     *
     * @return string
     */
    protected function range($start, $end)
    {
        $pages = array();

        // To generate the range of page links, we will iterate through each page
        // and, if the current page matches the page, we will generate a span,
        // otherwise we will generate a link for the page. The span elements
        // will be assigned the "current" CSS class for convenient styling.
        for ($page = $start; $page <= $end; $page++) {
            if ($this->page == $page) {
                $pages[] = '<li class="active"><a href="#">' . Helpers::getContainer('html')->entities(
                        $page
                    ) . '</a></li>';
            } else {
                $pages[] = '<li>' . $this->link($page, $page, null) . '</li>';
            }
        }

        return implode(' ', $pages);
    }
Example #19
0
 /**
  * Creates a table-wide row to display content
  *
  * @param string $content    The content to display
  * @param array  $attributes The rows's attributes
  * @param bool   $asHeaders  Draw row as header
  *
  * @return string A single-column row spanning all table
  */
 private function full_row($content, $attributes = array(), $asHeaders = false)
 {
     // Add a class for easy styling
     $attributes = Helpers::add_class($attributes, 'full-row');
     $tag = $asHeaders ? 'th' : 'td';
     return '<tr' . HTML::attributes($attributes) . '>
         <' . $tag . ' colspan="' . $this->numberColumns . '">' . $content . '</' . $tag . '>
     </tr>';
 }
Example #20
0
 /**
  * Allows creation of inverted navbar
  *
  * @param string $method     The method to call
  * @param array  $parameters An array of parameters
  *
  * @return Navbar
  */
 public static function __callStatic($method, $parameters)
 {
     if ($method == 'inverse') {
         $attributes = array_get($parameters, 0);
         $type = array_get($parameters, 1);
         $attributes = Helpers::add_class($attributes, 'navbar-inverse');
         return static::create($attributes, $type);
     } else {
         return static::create();
     }
 }
Example #21
0
 /**
  * Opens a new ButtonToolbar section.
  * @param array 	$attributes
  * @return string
  */
 public static function open($attributes = array())
 {
     $attributes = Helpers::add_class($attributes, 'btn-toolbar');
     return '<div' . HTML::attributes($attributes) . '>';
 }
 /**
  * Outputs the current Dropdown in instance
  *
  * @return string A Dropdown menu
  */
 public function __toString()
 {
     // Base class
     $this->attributes = Helpers::add_class($this->attributes, 'btn-group');
     // Pull right
     $listAttributes = $this->pullRight ? array('class' => 'pull-right') : array();
     // Dropup
     if ($this->dropup) {
         $this->attributes['class'] .= ' dropup';
     }
     $html = '<div' . HTML::attributes($this->attributes) . '>';
     //If split is false make this button dropdown
     $html .= Form::button($this->label, array('class' => $this->type), !$this->split);
     //Add split button if needed
     if ($this->split) {
         $html .= Form::button('', array('class' => $this->type), true);
     }
     $html .= Navigation::dropdown($this->links, $listAttributes, $this->autoroute);
     $html .= '</div>';
     return $html;
 }
Example #23
0
 /**
  * Generate an id of the form "x-class-name-x". These should always be
  * unique.
  *
  * @param \Bootstrapper\RenderedObject $caller The object that called this
  * @return string A unique id
  * @static 
  */
 public static function generateId($caller)
 {
     return \Bootstrapper\Helpers::generateId($caller);
 }
Example #24
0
 /**
  * Checks call to see if we can create a progress bar from a magic call (for you wizards).
  * normal_striped_active, info_striped, etc...
  *
  * @param string $method     Method name
  * @param array  $parameters Method parameters
  *
  * @return mixed
  */
 public static function __callStatic($method, $parameters)
 {
     $method_array = explode('_', strtolower($method));
     $types = array('normal', 'success', 'info', 'warning', 'danger', 'automatic');
     $type_found = array_intersect($method_array, $types);
     if (count($type_found) > 0) {
         $function = $type_found[key($type_found)];
         // Set default $attributes and check for a set value
         $attributes = array();
         if (isset($parameters[1])) {
             if (is_array($parameters[1])) {
                 $attributes = $parameters[1];
             } else {
                 throw new \InvalidArgumentException("Tabbable attributes parameter should be an array of attributes");
             }
         }
         if (in_array('striped', $method_array)) {
             $attributes = Helpers::add_class($attributes, 'progress-striped');
         }
         if (in_array('active', $method_array)) {
             $attributes = Helpers::add_class($attributes, 'active');
         }
         return static::$function($parameters[0], $attributes);
     }
 }
 /**
  * Prints out the MediaObject in memory
  *
  * @return string The HTML markup for the media object
  */
 public function __toString()
 {
     // Whether objects should be printed as list elements or divs
     $children = static::$listed ? 'li' : 'div';
     // Open the media object
     $attributes = Helpers::add_class($this->attributes, 'media');
     $html = '<' . $children . HTML::attributes($attributes) . '>';
     // Add the media itself
     $html .= '<a class="pull-' . $this->pull . '">';
     $html .= $this->media;
     $html .= '</a>';
     // Add the title and body
     $html .= '<div class="media-body">';
     if ($this->title) {
         $html .= $this->title;
     }
     $html .= $this->content;
     // Render nested media objects (always as divs)
     if ($this->nested) {
         $listed = static::$listed;
         static::$listed = false;
         foreach ($this->nested as $mediaObject) {
             $html .= $mediaObject;
         }
         static::$listed = $listed;
     }
     // Close body
     $html .= '</div>';
     // Close object
     $html .= '</' . $children . '>';
     return $html;
 }
Example #26
0
 /**
  * Create a new Label
  *
  * @param string $type       Label type
  * @param string $message    Label text
  * @param array  $attributes Attributes to apply the label itself
  *
  * @return string Label HTML
  */
 protected static function show($type = Label::NORMAL, $message, $attributes = array())
 {
     $attributes = Helpers::add_class($attributes, 'label ' . $type);
     return '<span' . HTML::attributes($attributes) . '>' . $message . '</span>';
 }
Example #27
0
 /**
  * Checks call to see if we can create a button from a magic call (for you wizards).
  * success_button, mini_primary_button, large_warning_submit, danger_reset, etc...
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return mixed
  */
 public static function __callStatic($method, $parameters)
 {
     $method_array = explode('_', strtolower($method));
     $btn_types = array('normal', 'submit', 'reset', 'link');
     $type_found = array_intersect($method_array, $btn_types);
     if (count($type_found) > 0) {
         $function = $type_found[key($type_found)];
         //Set default attributes index
         $attr_index = $function != 'link' ? 1 : 2;
         $parameters = Helpers::set_multi_class_attributes($function, $method_array, $parameters, $attr_index, 'btn-', 'disabled');
         if (in_array('disabled', $method_array)) {
             $parameters[$attr_index]['disabled'] = 'disabled';
         }
         return call_user_func_array('static::' . $function, $parameters);
     }
 }
Example #28
0
 /**
  * Prints the current button in memory
  *
  * @return string A button
  */
 public function __toString()
 {
     // Gather variables
     extract($this->currentButton);
     // Add btn to classes and fallback type
     if (!isset($attributes['type'])) {
         $attributes['type'] = 'button';
     }
     $attributes = Helpers::add_class($attributes, 'btn');
     // Modify output if we have a dropdown
     $caret = null;
     if ($hasDropdown) {
         $attributes = Helpers::add_class($attributes, 'dropdown-toggle');
         $caret = ' <span class="caret"></span>';
         $attributes['data-toggle'] = 'dropdown';
     }
     // Write output according to tag
     $tag = 'button';
     if ($type === 'link') {
         $tag = 'a';
         unset($attributes['type']);
     }
     return '<' . $tag . HTML::attributes($attributes) . '>' . (string) $value . $caret . '</' . $tag . '>';
 }
Example #29
0
    /**
     * Writes the current Alert
     *
     * @return string A Bootstrap Alert
     */
    public function render()
    {
        $this->addClass('alert');

        // Block alert
        if ($this->isBlock) {
            $this->addClass('alert-block');
        }

        // Add close icon if necessary
        if ($this->isCloseable) {
            $close = Helpers::getContainer('html')->link(
                '#',
                '&times;',
                array('class' => 'close', 'data-dismiss' => 'alert')
            );
            $this->nest($close);
        }

        $this->nest(new Text($this->message));

        return '<' . $this->element . Helpers::getContainer('html')->attributes(
            $this->attributes
        ) . '>' . $this->getContent() . $this->close();
    }
Example #30
0
    /**
     * Returns the latest version of Bootstrap's (and JQuery's) JS
     *
     * @return string The link for the latest version of Bootstrap
     */
    public static function get_JS()
    {
        $bootstrapVersion = Helpers::getContainer('config')->get('bootstrapper::bootstrap_version');
        $jQueryVersion = Helpers::getContainer('config')->get('bootstrapper::jquery_version');

        return "<script src='http://code.jquery.com/jquery-$jQueryVersion.min.js'></script><script src='//netdna.bootstrapcdn.com/bootstrap/$bootstrapVersion/js/bootstrap.min.js'></script>";
    }