Last active
December 18, 2015 00:08
-
-
Save dasch/5693878 to your computer and use it in GitHub Desktop.
Formatting Curly methods.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CurlyDoc | |
def self.documentation_for_method(method) | |
pretty_name = CurlyInfo.curly_name(method) | |
description = I18n.translate(method.name, namespace: "curly.methods") | |
"%s - %s" % [pretty_name, description] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CurlyInfo | |
# Formats the method nicely. | |
# | |
# method - A Method on a presenter class. | |
# | |
# Example | |
# | |
# class FunnyPresenter < Curly::Presenter | |
# def hello(somearg) | |
# ... | |
# end | |
# end | |
# | |
# method = FunnyPresenter.instance_method(:hello) | |
# CurlyInfo.curly_name(method) #=> "{{hello.somearg}}" | |
# | |
# Returns a String representing the method. | |
def self.curly_name(method) | |
if method.arity == 1 | |
parameter = method.parameters[0] | |
# First item is e.g. :req, second is the name. | |
argument_name = parameter[1] | |
"{{%s.<%s>}}" % [method.name, argument_name] | |
else | |
"{{%s}}" % method.name | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment