mattock 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,126 @@
1
+ require 'yard'
2
+ YARD::Templates::Engine.register_template_path File::expand_path("../../../yard_templates", __FILE__)
3
+
4
+ module Mattock
5
+ module YARDExtensions
6
+ class SettingHandler < YARD::Handlers::Ruby::Base
7
+ include YARD::Parser::Ruby
8
+
9
+ handles method_call(:setting)
10
+ namespace_only
11
+
12
+ def extract_name(obj)
13
+ case obj.type
14
+ when :symbol_literal
15
+ obj.jump(:ident, :op, :kw, :const)[0]
16
+ when :string_literal
17
+ obj.jump(:tstring_content)[0]
18
+ else
19
+ raise YARD::Parser::UndocumentableError, obj.source
20
+ end
21
+ end
22
+
23
+ def append_name(sexp, name)
24
+ prefix = sexp.jump(:ident, :string_content)
25
+ if prefix == sexp
26
+ raise YARD::Parser::UndocumentableError, sexp.source
27
+ end
28
+
29
+ "#{prefix[0]}.#{name}"
30
+ end
31
+
32
+ def synthetic_setting(name, value=nil)
33
+ args = s( s(:string_literal, s(:string_content, s(:tstring_content, name))))
34
+ args << value unless value.nil?
35
+ args << false
36
+ new_call = s(:fcall, s(:ident, "setting"), s(:arg_paren, args))
37
+ new_call.line_range = (1..1)
38
+ new_call.traverse do |node|
39
+ node.full_source ||= ""
40
+ end
41
+ new_call.full_source = "setting('#{name}'#{value.nil? ? "" : ", #{value.source}"})"
42
+ new_call
43
+
44
+ end
45
+
46
+ def process
47
+ #filter further based on NS === Configurable...
48
+ name = extract_name(statement.parameters.first)
49
+
50
+ value = statement.parameters(false)[1]
51
+ if !value.nil? and value.type == :fcall and value.jump(:ident)[0] == "nested"
52
+ remapped = value.parameters(false).first.map do |assoc|
53
+ new_name =
54
+ append_name(statement.parameters[0], extract_name(assoc[0]))
55
+ synthetic_setting(new_name, assoc[1])
56
+ end
57
+ parser.process(remapped)
58
+ return
59
+ end
60
+
61
+ setting = YARD::CodeObjects::MethodObject.new(namespace, name) do |set|
62
+ unless value.nil?
63
+ set['default_value'] = statement.parameters(false)[1].source
64
+ end
65
+ set.signature = "def #{name}"
66
+ if statement.comments.to_s.empty?
67
+ set.docstring = "The value of setting #{name}"
68
+ else
69
+ set.docstring = statement.comments
70
+ end
71
+
72
+ set.dynamic = true
73
+ end
74
+
75
+ register setting
76
+ (namespace[:settings] ||= []) << setting
77
+ end
78
+ end
79
+
80
+ class SettingsHandler < SettingHandler
81
+ handles method_call(:settings)
82
+ namespace_only
83
+
84
+ def process
85
+ remapped = statement.parameters(false).first.map do |assoc|
86
+ new_name =
87
+ append_name(statement.parameters[0], extract_name(assoc[0]))
88
+ synthetic_setting(new_name, assoc[1])
89
+ end
90
+ parser.process(remapped)
91
+ end
92
+ end
93
+
94
+ class NilFieldsHandler < SettingHandler
95
+ handles method_call(:nil_field)
96
+ handles method_call(:nil_fields)
97
+ namespace_only
98
+
99
+ def a_nil
100
+ v = s(:kw, nil)
101
+ v.full_source = "nil"
102
+ v
103
+ end
104
+
105
+ def process
106
+ remapped = statement.parameters(false).map do |name|
107
+ synthetic_setting(extract_name(name), a_nil)
108
+ end
109
+ parser.process(remapped)
110
+ end
111
+ end
112
+
113
+ class RequiredFieldsHandler < SettingHandler
114
+ handles method_call(:required_field)
115
+ handles method_call(:required_fields)
116
+ namespace_only
117
+
118
+ def process
119
+ remapped = statement.parameters(false).map do |name|
120
+ synthetic_setting(extract_name(name))
121
+ end
122
+ parser.process(remapped)
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,17 @@
1
+ require 'mattock'
2
+
3
+ describe Mattock::TemplateHost do
4
+ let :template_host do
5
+ Object.new.tap do |host|
6
+ host.extend Mattock::TemplateHost
7
+ def host.test_value; "A test value"; end
8
+ end
9
+ end
10
+
11
+ it "should be able to do easy templating" do
12
+ template_host.valise = Mattock::ValiseManager.default_valise("spec_help")
13
+ template_host.render("test.erb").should == "Templated: A test value\n"
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1 @@
1
+ require 'mattock/yard_extensions'
@@ -0,0 +1,35 @@
1
+ <li class="<%= @item.visibility %> <%= @item.has_tag?(:deprecated) ? 'deprecated' : '' %>">
2
+ <span class="summary_signature">
3
+ <% if @item.tags(:overload).size == 1 %>
4
+ <%= signature(@item.tag(:overload), true, !@item.attr_info) %>
5
+ <% else %>
6
+ <%= signature(@item, true, false, !@item.attr_info) %>
7
+ <% end %>
8
+
9
+ <% if @item.aliases.size > 0 %>
10
+ (also: <%= @item.aliases.map {|o| h(o.name(true)) }.join(", ") %>)
11
+ <% end %>
12
+ </span>
13
+ <% if @item.constructor? %>
14
+ <span class="note title constructor">constructor</span>
15
+ <% end %>
16
+ <% if rw = @item.attr_info %>
17
+ <% if rw[:read] && !rw[:write] %><span class="note title readonly">readonly</span><% end %>
18
+ <% if rw[:write] && !rw[:read] %><span class="note title writeonly">writeonly</span><% end %>
19
+ <% end %>
20
+ <% if @item.visibility != :public %><span class="note title <%= @item.visibility %>"><%= @item.visibility %></span><% end %>
21
+ <% if @item.has_tag?(:abstract) %><span class="abstract note title">Abstract</span><% end %>
22
+ <% if @item.has_tag?(:deprecated) %><span class="deprecated note title">Deprecated</span><% end %>
23
+ <% if @item.has_tag?(:api) && @item.tag(:api).text == 'private' %><span class="private note title">Private</span><% end %>
24
+
25
+ <% if @item.has_tag?(:deprecated) %>
26
+ <span class="summary_desc"><strong>Deprecated.</strong> <%= htmlify_line @item.tag(:deprecated).text %></span>
27
+ <% else %>
28
+ <span class="summary_desc"><%= htmlify_line docstring_summary(@item) %></span>
29
+ <% end %>
30
+ <% if !@item["default_value"] %>
31
+ <span class="summary_desc"><em>This setting must have a value set</em></span>
32
+ <%else%>
33
+ <span class="summary_desc">Default value: <code><%= @item["default_value"] %></code></span>
34
+ <%end%>
35
+ </li>
@@ -0,0 +1,8 @@
1
+ <% groups(object[:settings] || [], "Settings") do |list, name| %>
2
+ <h2><%= name %> <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
3
+ <ul class="summary">
4
+ <% list.each do |meth| %>
5
+ <%= yieldall :item => meth %>
6
+ <% end %>
7
+ </ul>
8
+ <% end %>
@@ -0,0 +1,15 @@
1
+ def init
2
+ super
3
+ sections.place(:settings, [:setting_summary]).before(:attribute_summary)
4
+ end
5
+
6
+ def prune_method_listing(list, hide_attrs=true)
7
+ list = super
8
+ list.reject do |o|
9
+ unless CodeObjects::Proxy === o.namespace or o.namespace[:settings].nil?
10
+ o.namespace[:settings].include?(o)
11
+ else
12
+ false
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mattock
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Judson Lester
@@ -110,12 +110,16 @@ extra_rdoc_files:
110
110
  - doc/coverage/assets/0.5.3/loading.gif
111
111
  - doc/coverage/assets/0.5.3/jquery-1.6.2.min.js
112
112
  files:
113
+ - yard_templates/default/module/setup.rb
114
+ - yard_templates/default/module/html/setting_summary.erb
115
+ - yard_templates/default/module/html/settings.erb
113
116
  - lib/mattock/command-line.rb
114
117
  - lib/mattock/command-task.rb
115
118
  - lib/mattock/testing/rake-example-group.rb
116
119
  - lib/mattock/testing/mock-command-line.rb
117
120
  - lib/mattock/testing/record-commands.rb
118
121
  - lib/mattock/template-host.rb
122
+ - lib/mattock/yard_extensions.rb
119
123
  - lib/mattock/remote-command-task.rb
120
124
  - lib/mattock/tasklib.rb
121
125
  - lib/mattock/task.rb
@@ -128,6 +132,8 @@ files:
128
132
  - spec/command-task.rb
129
133
  - spec/tasklib.rb
130
134
  - spec/configurable.rb
135
+ - spec/yard-extensions.rb
136
+ - spec/template-host.rb
131
137
  - spec_help/spec_helper.rb
132
138
  - spec_help/gem_test_suite.rb
133
139
  - doc/coverage/index.html
@@ -189,7 +195,7 @@ rdoc_options:
189
195
  - --main
190
196
  - doc/README
191
197
  - --title
192
- - mattock-0.2.0 RDoc
198
+ - mattock-0.2.1 RDoc
193
199
  require_paths:
194
200
  - lib/
195
201
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -197,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
203
  requirements:
198
204
  - - ">="
199
205
  - !ruby/object:Gem::Version
200
- hash: -1033845645
206
+ hash: 697578897
201
207
  segments:
202
208
  - 0
203
209
  version: "0"