Class: ApiDocGeneration::ViewHelper
- Inherits:
-
Object
- Object
- ApiDocGeneration::ViewHelper
- Defined in:
- lib/api_doc_generation/view_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#action_identifer(controller_name, action_name) ⇒ Object
Helper #######################.
- #controller_identifer(controller_name) ⇒ Object
- #format_other_param(param) ⇒ Object
- #format_param(param) ⇒ Object
- #format_response_param(param) ⇒ Object
-
#initialize(args) ⇒ ViewHelper
constructor
=> 1, :b => 2.
- #obj_binding ⇒ Object
-
#render(path, opts = {}) ⇒ Object
View Helper ###################.
Constructor Details
#initialize(args) ⇒ ViewHelper
=> 1, :b => 2
15 16 17 18 19 20 21 |
# File 'lib/api_doc_generation/view_helper.rb', line 15 def initialize(args) @args = args args.each do |key, val| self.instance_variable_set("@#{key}", val) end end |
Class Method Details
.render(template, args = {}, file_path = '') ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/api_doc_generation/view_helper.rb', line 4 def self.render(template, args = {}, file_path = '') template.result(self.new(args).obj_binding) rescue => e e.backtrace[0].gsub!(/^\(erb\)/, file_path) raise e end |
Instance Method Details
#action_identifer(controller_name, action_name) ⇒ Object
Helper #######################
46 47 48 |
# File 'lib/api_doc_generation/view_helper.rb', line 46 def action_identifer(controller_name, action_name) "action-#{Digest::MD5.hexdigest(controller_name)}-#{action_name}" end |
#controller_identifer(controller_name) ⇒ Object
51 52 53 |
# File 'lib/api_doc_generation/view_helper.rb', line 51 def controller_identifer(controller_name) "controller-#{Digest::MD5.hexdigest(controller_name)}" end |
#format_other_param(param) ⇒ Object
102 103 104 |
# File 'lib/api_doc_generation/view_helper.rb', line 102 def format_other_param(param) end |
#format_param(param) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/api_doc_generation/view_helper.rb', line 56 def format_param(param) return unless param['val'].to_s =~ /^\s*$/ case param['name'] when 'app_uname' param['type'] = 'String' param['val'] = 'app的唯一标识名,表明调用此api是在哪个app下' when 'access_token' param['type'] = 'String' param['val'] = '请求的唯一标识,用于识别用户,用户登陆返回或是使用refresh_token换取' when 'refresh_token' param['type'] = 'String' param['val'] = '用户登陆时返回,使用此token来取得新的access_token' when 'page' param['type'] = 'Integer' param['val'] = '返回所有数据中的第几页' when 'perpage' param['type'] = 'Integer' param['val'] = '返回数据每页多少条' end end |
#format_response_param(param) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/api_doc_generation/view_helper.rb', line 79 def format_response_param(param) return unless param['val'].to_s =~ /^\s*$/ case param['name'] when 'current_page' param['type'] = 'Integer' param['val'] = '当前返回数据是第几页' when 'perpage' param['type'] = 'Integer' param['val'] = '每页返回的数据量' when 'count' param['type'] = 'Integer' param['val'] = '数据总数量' when 'items' param['type'] = 'Array' param['val'] = '数组中存放当前页的数据' when 'total_pages' param['type'] = 'Integer' param['val'] = '数据的总页数' end end |
#obj_binding ⇒ Object
24 25 26 |
# File 'lib/api_doc_generation/view_helper.rb', line 24 def obj_binding binding end |
#render(path, opts = {}) ⇒ Object
View Helper ###################
33 34 35 36 37 38 39 40 41 |
# File 'lib/api_doc_generation/view_helper.rb', line 33 def render(path, opts = {}) path = "templates/_#{path}.*.erb" file_path = Dir[File.(path, ROOT_PATH)].first raise "no found file '#{path}'" unless file_path template = ERB.new(File.read(file_path)) self.class.render(template, @args.merge(opts), file_path) end |