Class: Ape::Samples

Inherits:
Object
  • Object
show all
Defined in:
lib/ape/samples.rb

Constant Summary collapse

@@service_schema =
nil
@@categories_schema =
nil
@@atom_schema =
nil

Class Method Summary collapse

Class Method Details

.atom_RNCObject



50
51
52
53
# File 'lib/ape/samples.rb', line 50

def Samples.atom_RNC
  @@atom_schema = load_schema('atom') unless @@atom_schema
  @@atom_schema
end

.basic_entryObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ape/samples.rb', line 78

def Samples.basic_entry
  eruby = load_template('basic_entry')      
   
  context = SamplesContext.new(        
    :title => Escaper.escape('From the <APE> (サル)'),
    :subject => Names::DcNamespace
  )
  context[:summary] = "Summary from the &lt;b>&amp;lt;&amp;nbsp;APE&amp;nbsp;>&lt;/b> at #{context.now}"
  
  eruby.evaluate(context)
end

.cat_test_entryObject



94
95
96
# File 'lib/ape/samples.rb', line 94

def Samples.cat_test_entry
  retitled_entry('Testing category posting')
end

.categories_RNCObject



45
46
47
48
# File 'lib/ape/samples.rb', line 45

def Samples.categories_RNC
  @@categories_schema = load_schema('categories') unless @@categories_schema
  @@categories_schema
end

.entry_path(type) ⇒ Object



63
64
65
66
67
# File 'lib/ape/samples.rb', line 63

def Samples.entry_path(type)
  File.exist?(File.join(::Ape.home, "/#{type}.eruby"))?
    File.join(::Ape.home, "/#{type}.eruby") :
    File.join(File.dirname(__FILE__), "/../../samples/#{type}.eruby")
end

.foreign_childObject



26
27
28
# File 'lib/ape/samples.rb', line 26

def Samples.foreign_child
  'subject'
end

.foreign_child_contentObject



32
33
34
# File 'lib/ape/samples.rb', line 32

def Samples.foreign_child_content
  'Simians'
end

.foreign_namespaceObject



29
30
31
# File 'lib/ape/samples.rb', line 29

def Samples.foreign_namespace
  Names::DcNamespace
end

.load_schema(file_name) ⇒ Object



36
37
38
# File 'lib/ape/samples.rb', line 36

def Samples.load_schema(file_name)
  IO.read(File.join(File.dirname(__FILE__), "/../../samples/#{file_name}_schema.txt"))      
end

.load_template(type) ⇒ Object



69
70
71
# File 'lib/ape/samples.rb', line 69

def Samples.load_template(type)
  Erubis::FastEruby.new(IO.read(entry_path(type)))      
end

.make_idObject



57
58
59
60
61
# File 'lib/ape/samples.rb', line 57

def Samples.make_id
  id = ''
  5.times { id += rand(1000000).to_s }
  "tag:tbray.org,2005:#{id}"
end

.mini_entryObject



74
75
76
# File 'lib/ape/samples.rb', line 74

def Samples.mini_entry
  load_template('mini_entry').evaluate(SamplesContext.new)      
end

.pictureObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/ape/samples.rb', line 104

def Samples.picture
b64 =<<END_OF_PICTURE
/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQE
BQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/
2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
FBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAA8AEYDASIAAhEBAxEB/8QA
HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUF
BAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK
FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1
dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG
x8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEB
AQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAEC
AxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvA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4OO2KonVLgblDAAcDAqAanO8+0kADngURoXbdvxZM8Y
001+n/Dk41B8ZaFmx8oyx6UVVn1m5jRCGXOMfdorRU2lqvx/4BhPFzlK6lb5
I//Z
END_OF_PICTURE
  Base64.decode64(b64)
end

.retitled_entry(new_title, new_id = nil) ⇒ Object



98
99
100
101
102
# File 'lib/ape/samples.rb', line 98

def Samples.retitled_entry(new_title, new_id = nil)
  e = basic_entry
  e.gsub!(/<title>.*<\/title>/, "<title>#{new_title}</title>")      
  e.gsub(/<id>.*<\/id>/, "<id>#{new_id}</id>") if new_id
end

.service_RNCObject



40
41
42
43
# File 'lib/ape/samples.rb', line 40

def Samples.service_RNC
  @@service_schema = load_schema('service') unless @@service_schema
  @@service_schema
end

.unclean_xhtml_entryObject



90
91
92
# File 'lib/ape/samples.rb', line 90

def Samples.unclean_xhtml_entry
  load_template('unclean_xhtml_entry').evaluate(SamplesContext.new)      
end