diff -u b/src/Plugin/Filter/GistFilter.php b/src/Plugin/Filter/GistFilter.php --- b/src/Plugin/Filter/GistFilter.php +++ b/src/Plugin/Filter/GistFilter.php @@ -10,28 +10,25 @@ 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; -use Drupal\gist_filter\GistFilterGitHubClient; -use Drupal\gist_filter\GistFilterCacheDecoratorClient; use Drupal\gist_filter\GitHubRequestException; use Drupal\Core\Routing\LinkGeneratorTrait; 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" - * } * ) */ class GistFilter extends FilterBase implements ContainerFactoryPluginInterface { @@ -46,7 +43,7 @@ protected $renderer; /** - * @var GistFilterGitHubClient + * @var \Drupal\gist_filter\GistFilterGitHubClient */ protected $gitHubClient; @@ -78,7 +75,7 @@ $configuration, $plugin_id, $plugin_definition, - new GistFilterCacheDecoratorClient(new GistFilterGitHubClient($container->get('http_client')), $container->get('cache.default')), + $container->get('gist_filter_cached_github_client'), $container->get('renderer'), $container->get('logger.factory')->get('filter') ); @@ -87,28 +84,11 @@ /** * {@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); } @@ -116,11 +96,13 @@ /** * {@inheritdoc} */ - public function tips($long = FALSE) { - $display = $this->settings['gist_filter_display_method']; - $action = $display == 'embed' ? $this->t('embed the gist') : $this->t('create a link to the gist'); + public function tips($long = true) { + + $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 $this->t('Use [gist:####] where #### is your gist number to %action.', array('%action' => $action)); + return $output; } diff -u b/src/Tests/GistFilterTestCase.php b/src/Tests/GistFilterTestCase.php --- b/src/Tests/GistFilterTestCase.php +++ b/src/Tests/GistFilterTestCase.php @@ -50,7 +50,6 @@ // Turn on our input filter and set the option to embed. $edit = array( 'filters[gist_filter][status]' => 1, - 'filters[gist_filter][settings][gist_filter_display_method]' => 'embed', ); $this->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration')); @@ -74,7 +73,6 @@ // Turn on our input filter and set the option to embed. $edit = array( 'filters[gist_filter][status]' => 1, - 'filters[gist_filter][settings][gist_filter_display_method]' => 'embed', ); $this->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration')); @@ -99,14 +97,13 @@ // Turn on our input filter and set the option to link. $edit = array( 'filters[gist_filter][status]' => 1, - 'filters[gist_filter][settings][gist_filter_display_method]' => 'link', ); $this->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration')); $edit = array( 'title[0][value]' => $this->randomMachineName(), - 'body[0][value]' => 'Hello! [gist:865412]', + 'body[0][value]' => 'Hello! [gistlink:865412]', ); $this->drupalPostForm('node/add/' . $this->contentType->id(), $edit, t('Save')); @@ -120,17 +117,16 @@ */ public function testLinkStyleWithFile() { - // Turn on our input filter and set the option to link. + // Turn on our input filter. $edit = array( 'filters[gist_filter][status]' => 1, - 'filters[gist_filter][settings][gist_filter_display_method]' => 'link', ); $this->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration')); $edit = array( 'title[0][value]' => $this->randomMachineName(), - 'body[0][value]' => 'Hello! [gist:865412:php_file.php]', + 'body[0][value]' => 'Hello! [gistlink:865412:php_file.php]', ); $this->drupalPostForm('node/add/' . $this->contentType->id(), $edit, t('Save')); @@ -144,17 +140,16 @@ */ public function testCodeTagStyle() { - // Turn on our input filter and set the option to code. + // Turn on our input filter. $edit = array( 'filters[gist_filter][status]' => 1, - 'filters[gist_filter][settings][gist_filter_display_method]' => 'code', ); $this->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration')); $edit = array( 'title[0][value]' => $this->randomMachineName(), - 'body[0][value]' => 'Hello! [gist:865412]', + 'body[0][value]' => 'Hello! [gistcode:865412]', ); $this->drupalPostForm('node/add/' . $this->contentType->id(), $edit, t('Save')); only in patch2: unchanged: --- /dev/null +++ b/README.md @@ -0,0 +1,61 @@ +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 partly ported by a Google Code-In student. + + * 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 only in patch2: unchanged: --- 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