Class: Marv::Project::Functions

Inherits:
Object
  • Object
show all
Defined in:
lib/marv/project/builder/functions.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder) ⇒ Functions

Initialize functions builder



6
7
8
9
10
11
# File 'lib/marv/project/builder/functions.rb', line 6

def initialize(builder)
  @builder = builder
  @task = builder.task
  @project = builder.project
  @config = builder.project.config
end

Instance Method Details

#clean_foldersObject

Clean folders



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/marv/project/builder/functions.rb', line 71

def clean_folders
  @task.shell.mute do
    # Clean extra folder from project root
    extra_folders.each do |folder|
      source = folder.gsub(@project.source_path, '')
      target = ::File.join(@project.build_path, source)

      @task.remove_dir target
    end
  end
end

#clean_functionsObject

Clean functions



14
15
16
17
18
19
20
21
22
23
# File 'lib/marv/project/builder/functions.rb', line 14

def clean_functions
  @task.shell.mute do
    #remove functions and plugin php
    @task.remove_file ::File.join(@project.build_path, ::File.basename(@project.functions_file))
    @task.remove_file ::File.join(@project.build_path, ::File.basename(@project.plugin_file))

    # Remove functions folder
    @task.remove_dir ::File.join(@project.build_path, 'functions')
  end
end

#clean_includesObject

Clean includes



52
53
54
55
56
# File 'lib/marv/project/builder/functions.rb', line 52

def clean_includes
  @task.shell.mute do
    @task.remove_dir ::File.join(@project.build_path, 'includes')
  end
end

#copy_foldersObject

Copy folders



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/marv/project/builder/functions.rb', line 84

def copy_folders
  @task.shell.mute do
    # Copy extra folders to project root
    extra_folders.each do |folder|
      source = folder.gsub(@project.source_path, '')
      target = ::File.join(@project.build_path, source)

      @task.directory folder, target, :force => true
    end
  end
end

#copy_functionsObject

Copy functions



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/marv/project/builder/functions.rb', line 26

def copy_functions
  @task.shell.mute do
    files = copy_functions_files

    ::Dir.glob(::File.join(@project.functions_path, '*')).each do |file|
      unless files.include?(file)
        @task.copy_file file, ::File.join(@project.build_path, 'functions', ::File.basename(file)), :force => true
      end
    end
  end
end

#copy_functions_filesObject

Copy functions



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/marv/project/builder/functions.rb', line 39

def copy_functions_files
  files = [@project.functions_file, @project.plugin_file]

  ::Dir.glob(::File.join(@project.functions_path, '*')).each do |file|
    if files.include?(file)
      @task.copy_file file, ::File.join(@project.build_path, ::File.basename(file)), :force => true
    end
  end

  return files
end

#copy_includesObject

Copy includes



59
60
61
62
63
64
65
66
67
68
# File 'lib/marv/project/builder/functions.rb', line 59

def copy_includes
  @task.shell.mute do
    ::Dir.glob(::File.join(@project.includes_path, '**', '*')).each do |file|
      source = file.gsub(@project.source_path, '')
      target = ::File.join(@project.build_path, source)

      @task.copy_file file, target, :force => true unless ::File.directory?(file)
    end
  end
end

#extra_foldersObject

Extra folders



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/marv/project/builder/functions.rb', line 97

def extra_folders
  default = ['assets', 'functions', 'includes', 'templates']
  folders = []
  # Remove marv folders from root path
  ::Dir.glob(::File.join(@project.source_path, '*')).each do |folder|
    if ::File.directory?(folder) and ! default.include?(::File.basename(folder))
      folders << folder
    end
  end
  # Return folders array
  return folders
end