Class: RuneBlog::View

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/runeblog_version.rb,
lib/view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#copy_data, #find_draft_slugs, #get_all_widgets, #get_repo_config, #get_widget, #new_sequence, #quit_RubyText, #read_features, #read_vars, #subdirs, #write_features, #write_repo_config

Constructor Details

#initialize(name) ⇒ View

Returns a new instance of View.

Raises:

  • (NoBlogAccessor)


9
10
11
12
13
14
15
16
17
18
# File 'lib/view.rb', line 9

def initialize(name)
  log!(enter: __method__, args: [name], level: 3)
  raise NoBlogAccessor if RuneBlog.blog.nil?
  @blog = RuneBlog.blog
  @name = name
  @publisher = RuneBlog::Publishing.new(name)
  @can_publish = true  # FIXME
  #  @blog.view = self  # NOOOO??
  get_globals
end

Instance Attribute Details

#globalsObject

Returns the value of attribute globals.



5
6
7
# File 'lib/view.rb', line 5

def globals
  @globals
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/view.rb', line 4

def name
  @name
end

#publisherObject

Returns the value of attribute publisher.



5
6
7
# File 'lib/view.rb', line 5

def publisher
  @publisher
end

#stateObject (readonly)

Returns the value of attribute state.



4
5
6
# File 'lib/view.rb', line 4

def state
  @state
end

Instance Method Details

#can_publish?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/view.rb', line 75

def can_publish?
  @can_publish
end

#dirObject



59
60
61
# File 'lib/view.rb', line 59

def dir
  @blog.root + "/views/#@name/"
end

#dump_globals_stderrObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/view.rb', line 20

def dump_globals_stderr
  log!(enter: __method__, args: [list], level: 2)
  list2 = list.select(&block)
  STDERR.puts "-- globals = "
  log!(str: "-- globals = ")
  @globals.each_pair do |k, v| 
    msg = sprintf "     %-10s  %s\n", k, v if k.is_a? Symbol 
    STDERR.puts msg
  log!(str: msg)
  end
  STDERR.puts 
  log!(str: "")
end

#get_globals(force = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/view.rb', line 34

def get_globals(force = false)
  return if @globals && !force

  # gfile = @blog.root/"views/#@name/themes/standard/global.lt3"
  gfile = @blog.root/"views/#@name/data/global.lt3"
  return unless File.exist?(gfile)  # Hackish!! how is View.new called from create_view??

  live = Livetext.customize(call: ".nopara")
puts "get_globals - 1 - transforming #{gfile}"
  # FIXME - error here somehow:
  # get_globals - 1 - transforming /private/tmp/.blogs/views/foobar/data/global.lt3
  # >> variables: pre="view"  file="../settings/view.txt" pwd=/private/tmp
  # No such dir "../settings" (file ../settings/view.txt)
  # No such dir "../settings" (file ../settings/view.txt)
  # get_globals - 2
  live.xform_file(gfile)
puts "get_globals - 2"
  live.setvar("ViewDir", @blog.root/:views/@name)
puts "get_globals - 3"
  live.setvar("View",    @name)
puts "get_globals - 4"
  @globals = live.vars
#   dump_globals_stderr
end

#indexObject



67
68
69
# File 'lib/view.rb', line 67

def index
  dir + "index.html"
end

#local_indexObject



63
64
65
# File 'lib/view.rb', line 63

def local_index
  dir + "/remote/index.html"
end

#recent?(file) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
# File 'lib/view.rb', line 79

def recent?(file)
  File.mtime(file) > File.mtime("#{self.dir()}/last_published")
rescue
  true
end

#to_sObject



71
72
73
# File 'lib/view.rb', line 71

def to_s
  @name
end