Code Monkey home page Code Monkey logo

Comments (5)

kevinranks avatar kevinranks commented on August 16, 2024

Hey Art!

Great write up you've put together here, thanks for putting in the time for this contribution. I really like where you're going with it, especially the fact that you've included backward compatibility for the current static class.

I was wondering if separating the config from the client is purely for organization best practices or if there was another reason?

DB Generated

  • $shortcode_replace
  • $ascii_replace
  • $unicode_replace
  • $asciiRegexp

Not DB generated

  • $ignoredRegexp - This regular expression was written manually. it's used in combination with the other expressions in the class. If we wanted to add additional tags for the replacements to ignore, we'd update this manually. I think it's ok for people to contribute to and modify.
  • $unicodeRegexp - This is a manually written expression (thanks @s9e!) that covers all of our current unicode code blocks. If a new code block was ever added, this would have to be manually updated.

from emojione.

Art4 avatar Art4 commented on August 16, 2024

I was wondering if separating the config from the client is purely for organization best practices or if there was another reason?

I'm not sure if seperating config from the client is best practice. My intension was to make it possible to write a custom client but using the default config. And it seperates the logic from config. But it isn't necessary and I can put config and client together. We can split theses things in future if needed.

Thank you for declaration the parameters. I will writeup two interfaces (RulesetInterface and ClientInterface) for the next steps and update the plan. But first I will open a PR for moving to namespace Emojione.

from emojione.

emitxyz avatar emitxyz commented on August 16, 2024

We are gonna close this issue for now as there hasn't been activity on it for awhile, but we can reopen it again later if you want. Thanks for your contributions, always appreciated. :)

from emojione.

Art4 avatar Art4 commented on August 16, 2024

Ok. :-) Unfortunately I don't have the time to contribute atm. I'll work on it later.

from emojione.

Art4 avatar Art4 commented on August 16, 2024

Ok, we're getting closer to use Emojione in our project and I will take the time to refactor the code. I put some thoughts and the above comments together and create this updated plan:

Writing tests

To make sure that the refactored code works as expected, we need some tests.

Split the class

Then It would be easy to split the class into 2(+1) Parts:

  1. Emojione\Ruleset This class implements RulesetInterface and is generated by the database. It should have a big notice on top not to modify the file.
  2. Emojione\Client This class does the main work and implements Emojione\ClientInterface``. It requires aRulesetInterfaceobject and has the configuration and all existing methods liketoShort(),shortnameToImage() ,toImage($str) ```, etc.

This would allow to build a client with fully customizable configuration:

// Default or custom ruleset
$ruleset = new Emojione\Ruleset;
$ruleset = new My\Own\Ruleset;

// load the emojione client
$client = new Emojione\Client($ruleset);
// or use your own client
$client = new My\Own\Client($ruleset);

// client configuration
$client->useSprites(true);
$client->addShortcode(':youtube:', 'icon_youtube.png');

// client usage
$client->toShort('Hello world! 😄');
// returns "Hello world! :smile:"

+1. Emojione\Emojione This is a static flyweight. It provides the simple PHP Conversion like the current Emolione.php but works with the client behind the scene. This will also be need for backward compatibility.

// behind the scene: inside Emojione\Emojione
public static toShort($str)
{
    $ruleset = new Ruleset;
    $client = new Client($ruleset);

    return $client->toShort($str);
}

// usage
Emojione\Emojione::toShort('Hello world! 😄');
// returns "Hello world! :smile:"

Emojione\Ruleset

The generated parts will be the default ruleset in Emojione\Ruleset and will implement Emojione\RulesetInterface. It will have a big notice on top like "Autogenerated. Do not edit this file".

It has this parameters:

  • $shortcode_replace
  • $ascii_replace
  • $unicode_replace
  • $asciiRegexp

Emojione\Client

All other parameters will be set in Emojione\Client`:

  • protected $ascii = false; // convert ascii smileys?
  • protected $unicodeAlt = true; // use the unicode char as the alt attribute (makes copy and pasting the resulting text better)
  • protected $imageType = 'png';
  • protected $sprites = false;
  • protected $imagePathPNG = '//cdn.jsdelivr.net/emojione/assets/png/';
  • protected $imagePathSVG = '//cdn.jsdelivr.net/emojione/assets/svg/';
  • protected $imagePathSVGSprites = './../assets/sprites/emojione.sprites.svg';
  • protected $unicode_replaceWith = false;
  • protected $shortcodeRegexp = ':([-+\w]+):';
  • protected $ignoredRegexp = '<object[^>]>.?</object>|<span...';
  • protected $unicodeRegexp = '(#0-9?\xE2...';

from emojione.

Related Issues (20)

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.