Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] General Refactoring #46

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

stex
Copy link

@stex stex commented Apr 9, 2017

Followup to #31

This PR moves the gem's asset files to vendor/assets and refactors most of its code, making its API more powerful.

Assets now reside in vendor/assets/gemojione
This makes loading the files into Rails' asset pipeline a lot easier as it is already searching in the corresponding gem directories.

This change also includes a new helper method to add the correct paths to the precompile list:

# Precompile all SVG emoji and the sprite image, but no PNG images
config.assets.precompile += Gemojione.asset_paths(formats: %i(svg sprites))

The stylesheet can now be @imported directly through the asset pipeline without any configuration

@import 'gemojione';

Replaced class attributes with an actual configuration object
Gemojione.configuration now returns a configuration object which may be used to customize the gem's workings.
This cleans the Gemojione module of these additional methods and makes testing the configuration itself a bit easier.

# Example from the railtie
initializer 'gemojione.defaults' do
  Gemojione.configuration.asset_host = ActionController::Base.asset_host
  Gemojione.configuration.asset_path = 'gemojione'
end

The API methods accept configuration options
It is still possible to specify whether to use sprites or the requested image format through the global configuration, but now these options may also be specified directly within the Gemojione API call:

Gemojione.image_url_for_name('heart', image_format: :png)
Gemojione.replace_named_moji_with_images('I :heart: Emoji', use_sprites: false, image_format: :svg)
'I :heart: Emoji'.with_emoji_from_names(use_sprites: false, image_format: :png)

The fallback value here is always the global configuration.

Rails' asset_url method is used when available
The ApplicationController.helpers proxy is used if it's available. This makes the URL generation for assets within the asset pipeline easier than having the developer to manually specify the URL components, including the host.

Regarding this, I noticed that the SCSS file contains the image-path helper. As far as I know, this means, that sprockets is a dependency when using this file, this should be mentioned in the README.


@jonathanwiesel This is still a WIP, I just wanted to keep you updated (it's been a long time again, sorry).

I'm trying to keep the Gem as separated from Rails as possible, though I'm guessing that it will be mainly used in Rails applications.

Still TODO:

  • Update tests for Gemojione module
  • Index refactoring
  • Full Rubocop compliance (with a bit of custom configuration)
  • Rake task updates regarding stylesheet generation
  • README updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant