Comments (5)
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.
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.
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.
Ok. :-) Unfortunately I don't have the time to contribute atm. I'll work on it later.
from emojione.
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:
- 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. - Emojione\Client This class does the main work and implements
Emojione\ClientInterface``. It requires a
RulesetInterfaceobject and has the configuration and all existing methods like
toShort(),
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)
- Problems with ️FE0F character HOT 2
- Minified lib has broken RegExps HOT 7
- README.md for fonts contains broken links HOT 1
- Problematic second colon in shortcode for ☀️ (:sunny:️) HOT 7
- Packagist is out of date HOT 2
- Q: Flutter/Dart support HOT 3
- Update emoji(-strategy).json and awesome.map to 4.5 HOT 1
- Upgrade iOS library to 4.5 HOT 1
- iOS font uses emoji number characters for plaintext numbers HOT 1
- getting question mark instead of emojis
- what are these 5 lines for? HOT 1
- Edit IOS font file HOT 1
- Missing genders HOT 3
- [REQUEST] Why Doesn't Release the JoyPixels 5.0? HOT 3
- Emojione v4.5 not working on Android 5.0 (lower versions work) HOT 5
- Joypixels 4.5 with another police HOT 1
- joypixels stickers installation HOT 1
- Missing skin tone modifiers for “🤝” (U+1F91D) and “🤼” (U+1F93C) HOT 1
- Get some emoji error HOT 2
- @jbrecht this is a great catch, thank you for pointing it out. It does appear that the gender for codepoints without `2640` are not being correctly set in the emoji.json file. Woman Astronaut should have a `gender` value of `2640` (the base code point of the female sign). We'll make the adjustments and get this published as soon as possible. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emojione.