Skip to content

Commit

Permalink
Use underscore_names instead of camelCasing for option keys
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Jan 8, 2015
1 parent d937a6d commit 0b6f011
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Block/Renderer/BlockQuoteRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public function render(AbstractBlock $block, HtmlRenderer $htmlRenderer, $inTigh

$filling = $htmlRenderer->renderBlocks($block->getChildren());
if ($filling === '') {
return new HtmlElement('blockquote', array(), $htmlRenderer->getOption('innerSeparator', "\n"));
return new HtmlElement('blockquote', array(), $htmlRenderer->getOption('inner_separator', "\n"));
}

return new HtmlElement(
'blockquote',
array(),
$htmlRenderer->getOption('innerSeparator', "\n") . $filling . $htmlRenderer->getOption('innerSeparator', "\n")
$htmlRenderer->getOption('inner_separator', "\n") . $filling . $htmlRenderer->getOption('inner_separator', "\n")
);
}
}
4 changes: 2 additions & 2 deletions src/Block/Renderer/ListBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public function render(AbstractBlock $block, HtmlRenderer $htmlRenderer, $inTigh
return new HtmlElement(
$tag,
$attr,
$htmlRenderer->getOption('innerSeparator', "\n") . $htmlRenderer->renderBlocks(
$htmlRenderer->getOption('inner_separator', "\n") . $htmlRenderer->renderBlocks(
$block->getChildren(),
$block->isTight()
) . $htmlRenderer->getOption('innerSeparator', "\n")
) . $htmlRenderer->getOption('inner_separator', "\n")
);
}
}
6 changes: 3 additions & 3 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,9 @@ public static function createCommonMarkEnvironment()
$environment->addExtension(new CommonMarkCoreExtension());
$environment->mergeConfig(array(
'renderer' => array(
'blockSeparator' => "\n",
'innerSeparator' => "\n",
'softBreak' => "\n",
'block_separator' => "\n",
'inner_separator' => "\n",
'soft_break' => "\n",
)
));

Expand Down
15 changes: 14 additions & 1 deletion src/HtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public function __construct(Environment $environment)
*/
public function getOption($option, $default = null)
{
// Handle deprecated config names
$configNames = array(
'blockSeparator' => 'block_separator',
'innerSeparator' => 'inner_separator',
'softBreak' => 'soft_break',
);
if (isset($configNames[$option])) {
$msg = sprintf('The "%s" option name has been deprecated - use "%s" instead.', $option, $configNames[$option]);
trigger_error($msg, E_USER_DEPRECATED);

$option = $configNames[$option];
}

// Deprecated retrieval method
if (isset($this->options[$option])) {
return $this->options[$option];
Expand Down Expand Up @@ -149,7 +162,7 @@ public function renderBlocks($blocks, $inTightList = false)
$result[] = $this->renderBlock($block, $inTightList);
}

$separator = $this->getOption('blockSeparator', "\n");
$separator = $this->getOption('block_separator', "\n");

return implode($separator, $result);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Inline/Renderer/NewlineRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function render(AbstractInline $inline, HtmlRenderer $htmlRenderer)
if ($inline->getType() === Newline::HARDBREAK) {
return new HtmlElement('br', array(), '', true) . "\n";
} else {
return $htmlRenderer->getOption('softBreak', "\n");
return $htmlRenderer->getOption('soft_break', "\n");
}
}
}

2 comments on commit 0b6f011

@melyux
Copy link

@melyux melyux commented on 0b6f011 Jan 11, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up, the changelog for 0.6 says the opposite of what was changed here.

"Renderer option names changed from underscore_case to camelCase (#56)"

(supposed to say "camelCase to underscore_case")

@colinodell
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this! I've updated the changelog accordingly.

Please sign in to comment.