diff -u b/README.md b/README.md --- b/README.md +++ b/README.md @@ -11,8 +11,8 @@ ------------ Gist Input Filter is the easiest way to embed Gists in your Drupal website. -It substitutes [gist:xx] tags with the gist located at gist.github.com/xx.Read -more about on how to use the Gist Input Filter module below. +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 ------------ @@ -25,21 +25,25 @@ ------------- * 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'. - - * Once you have enabled Gist Input Filter, you can change the embed method - under 'CKEditor plugin settings'. Three methods are available: Embed, which - will embed your gist, Code, which will display only the code contents of - your Gist, and Link, which will display the link to your Gist. + 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:#####] where ##### is the -number of your gist. You may also include a specific file within a multi-file -gist with [gist:#####:my_file]. +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 ----------- 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,7 +10,6 @@ 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,16 +19,16 @@ 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 { @@ -85,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); } @@ -115,10 +97,9 @@ * {@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; 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'));