Skip to content

Instantly share code, notes, and snippets.

@dasch
Last active December 18, 2015 00:08
Show Gist options
  • Save dasch/5693878 to your computer and use it in GitHub Desktop.
Save dasch/5693878 to your computer and use it in GitHub Desktop.
Formatting Curly methods.
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
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