Giter VIP home page Giter VIP logo

bb-rest's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

aberkow jfoc brandld

bb-rest's Issues

CSS and JS always empty in the object returned by fl-builder/v1/123

The REST API call fl-builder/v1/123 returns an object with the properties id, html, css and js. The two latter are always empty strings. Following implementation of FL_Rest_Content::callback() works as expected:

static function callback( $request ) {

  $post_id = FL_Rest::get_id( $request );

  ob_start();
  \FLBuilder::render_content_by_id( $post_id );
  $output->html = ob_get_clean();

  \FLBuilderModel::set_post_id( $post_id );
  $output->css = FLBuilder::render_css(false);
  $output->js = FLBuilder::render_js(false);
  \FLBuilderModel::reset_post_id();

}

FL_Rest::strip_spaces() introduces errors in Javascript code

FL_Rest::strip_spaces() is intended as "the poor man's" Javascript magnifier; it removes all white spaces in the Javascript. Unfortunately, it can introduce errors.

Some examples how bb-plugin/modules/post-grid/js/frontend.js is mangled by this method:

  • The lack of terminating semicolon on line 122 (which is valid JavaScript, although not recommend) creates syntax error when the white space is removed.

  • return path on line 160 is mangled to returnpath which gives syntax error.

  • The comment on line 215 will after removal of white spaces stretch to the end of the file.

One solution is to replace preg_replace('/[\n\r\t\s]/', '', $txt ) with

preg_replace(["/\s+[\r\n]/", "/[\r\n]\s+/", "/[\t ]+/"], ["\n", "\n ", " "], $txt )

Here is a patch doing just that:

`diff --git a/classes/class-fl-builder-rest.php b/classes/class-fl-builder-rest.php
index 7c294d3..606c119 100644
--- a/classes/class-fl-builder-rest.php
+++ b/classes/class-fl-builder-rest.php
@@ -18,6 +18,6 @@ final class FL_Rest{
        }
 
        static function strip_spaces( $txt ) {
-               return preg_replace('/[\n\r\t\s]/', '', $txt );
+               return preg_replace(["/\s+[\r\n]/", "/[\r\n]\s+/", "/[\t ]+/"], ["\n", "\n ", " "], $txt );
        }
 }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.