diff --git a/README.md b/README.md new file mode 100644 index 0000000..3a1d30b --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +CONTENTS OF THIS FILE +--------------------- + + * Introduction + * Installation + * Configuration + * Usage Instructions + * Maintainers + +INTRODUCTION +------------ + +Gist Input Filter is the easiest way to embed Gists in your Drupal website. +It substitutes [gist:xx] tags with the gist located at http://gist.github.com/xx. +Read more about on how to use the Gist Input Filter module below. + +INSTALLATION +------------ + + * Install as you would normally install a contributed Drupal module. Visit: + https://drupal.org/docs/8/extending-drupal-8/installing-drupal-8-modules + for further information. + +CONFIGURATION +------------- + + * Head to admin/config/content/formats, and click Configure button that's next + to the editor with which you want to use Gist Input Filter. Scroll down until + you see the 'Enabled filters' section. You will find 'Gist filter' below it. + Tick the checkbox, scroll down and click 'Save Configuration'. + +USAGE INSTRUCTIONS +------------------ + +To add a gist to a post, simply add [gist{display_method}:#####] where ##### is the +number of your gist and {display_method} is the way you want to display your gist. +Depending on the tag you used, Git Input Filter will replace: + + * [gist:xx] tags with the gist located at "http://gist.github.com/xx" and will +display it in a fully embedded format. + * [gistcode:xx] tags with the gist located at "http://gist.github.com/xx", and +will display only the code content of your gist. + * [gistlink:xx] tags with the "http://gist.github.com/xx" link. + +You may also include a specific file within a multi-file gist with +[gist:#####:my_file]. + +MAINTAINERS +----------- + +Current maintainers: + + * Kifah Meeran (Kifah Meeran) - https://drupal.org/user/3509455 + * Florian Latzel (fl3a) - https://www.drupal.org/u/fl3a + * Toño de Pedro (capuleto) - https://www.drupal.org/u/capuleto + +This project has been sponsored by: + + * GOOGLE CODE-IN + Google Code-In is an international contest for high-school students that + allows them to contribute to open source projects while earning cool + prizes. See more here: http://g.co/gci + diff --git a/gist_filter.info b/gist_filter.info deleted file mode 100644 index f92eb0d..0000000 --- a/gist_filter.info +++ /dev/null @@ -1,11 +0,0 @@ -name = Gist Input Filter -description = "Provides the ability to embed gists from Github." - -; Core version (required) -core = 7.x - -; Package name (see http://drupal.org/node/101009 for a list of names) -package = Input filters - -; Additional files -files[] = gist_filter.test diff --git a/src/Plugin/Filter/GistFilter.php b/src/Plugin/Filter/GistFilter.php index bf26257..3fa2765 100644 --- a/src/Plugin/Filter/GistFilter.php +++ b/src/Plugin/Filter/GistFilter.php @@ -10,7 +10,6 @@ namespace Drupal\gist_filter\Plugin\Filter; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\Form\FormStateInterface; use Drupal\filter\FilterProcessResult; use Drupal\filter\Plugin\FilterBase; use Drupal\gist_filter\GistFilterClientInterface; @@ -20,12 +19,15 @@ use Drupal\Core\Render\RendererInterface; use Drupal\Core\Url; /** - * Provides a filter to substitute [gist:xx] tags with the gist located at "http://gist.github.com/xx". + * Provides a filter to substitute: + * [gist:xx] tags with the gist located at "http://gist.github.com/xx" and will display it in a fully embedded format. + * [gistcode:xx] tags with the gist located at "http://gist.github.com/xx", and will display only the code. + * [gistlink:xx] tags with the "http://gist.github.com/xx" link. * * @Filter( * id = "gist_filter", * title = @Translation("Gist filter (Github Gists)"), - * description = @Translation("Substitutes [gist:xx] tags with the gist located at http://gist.github.com/xx.'"), + * description = @Translation("Substitutes [gist:xx] tags with the gist located at http://gist.github.com/xx. See the README learn about more ways to embed gists."), * type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE, * settings = { * "gist_filter_display_method" = "embed" @@ -82,31 +84,14 @@ class GistFilter extends FilterBase implements ContainerFactoryPluginInterface { ); } - /** - * {@inheritdoc} - */ - public function settingsForm(array $form, FormStateInterface $form_state) { - $form['gist_filter_display_method'] = array( - '#title' => $this->t('Gist display method'), - '#type' => 'select', - '#options' => array( - 'code' => $this->t('Code tags'), - 'embed' => $this->t('Embed'), - 'link' => $this->t('Link'), - ), - '#default_value' => $this->settings['gist_filter_display_method'], - ); - - return $form; - } - /** * {@inheritdoc} */ public function process($text, $language) { - $display = $this->settings['gist_filter_display_method']; - $callback = 'gistDisplay' . ucfirst($display); - $text = preg_replace_callback('@\[gist\:(?[\w/]+)(?:\:(?[\w\.]+))?\]@', array($this, $callback), $text); + + $text = preg_replace_callback('@\[gist\:(?[\w/]+)(?:\:(?[\w\.]+))?\]@', array($this, gistDisplayEmbed), $text); + $text = preg_replace_callback('@\[gistcode\:(?[\w/]+)(?:\:(?[\w\.]+))?\]@', array($this, gistDisplayCode), $text); + $text = preg_replace_callback('@\[gistlink\:(?[\w/]+)(?:\:(?[\w\.]+))?\]@', array($this, gistDisplayLink), $text); return new FilterProcessResult($text); } @@ -115,10 +100,9 @@ class GistFilter extends FilterBase implements ContainerFactoryPluginInterface { * {@inheritdoc} */ public function tips($long = true) { - $display = $this->settings['gist_filter_display_method']; - $action = $display == 'embed' ? $this->t('embed the gist') : $this->t('create a link to the gist'); - $output = $this->t('Use [gist:#####] where ##### is your gist number to %action', array('%action' => $action)) . '
'; + $output = $this->t('Use [gist:#####] for using the default embed method.', '
'; + $output = $this->t('You can use [gist:#####] for displaying just the code of your gist, or [gistlink:#####] for displaying the link of your gist.', '
'; $output.= $this->t('You may also include a specific file within a multi-file gist with [gist:####:my_file].'); return $output;