Class: Frap::Generators::FlutterResource

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/frap/generators/flutter_resource.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



13
14
15
# File 'lib/frap/generators/flutter_resource.rb', line 13

def self.source_root
  File.dirname(__FILE__) + '/templates/dart'
end

Instance Method Details

#configure_directoriesObject



17
18
19
# File 'lib/frap/generators/flutter_resource.rb', line 17

def configure_directories
  invoke :create_directories
end

#connect_widgetsObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/frap/generators/flutter_resource.rb', line 42

def connect_widgets
  inject_into_file("#{src_directory}/config/router.dart", router_packages, after: /^import 'package:flutter\/material.dart';$/)
  inject_into_file("#{src_directory}/config/router.dart", show_screen_router, after: /^.*switch \(settings.name\) \{$/)
  inject_into_file("#{src_directory}/config/router.dart", index_screen_router, after: /^.*switch \(settings.name\) \{$/)
  inject_into_file("#{src_directory}/constants/pages_list.dart", index_screen_route, after: /const List<Page> pages = const <Page>\[.*$/)
  inject_into_file("#{src_directory}/resources/repository.dart", repository_packages, after: /^import 'dart:async';$/)
  inject_into_file("#{src_directory}/resources/repository.dart", repository_body, after: /^class Repository \{$/)
  append_to_file("#{src_directory}/constants/routing.dart", "const String #{name}IndexScreenRoute = '/#{lower_name.pluralize }'; \n")
  append_to_file("#{src_directory}/constants/routing.dart", "const String #{name}ShowScreenRoute = '/#{lower_name.singularize}';\n")
  # build detail screen with bottom navigations
  # Link navigation buttons to Edit and back to list and delete
end

#create_directoriesObject



21
22
23
24
25
# File 'lib/frap/generators/flutter_resource.rb', line 21

def create_directories
  empty_directory("#{lib_directory}/src/screens/#{lower_name}")

  invoke :create_files
end

#create_filesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/frap/generators/flutter_resource.rb', line 27

def create_files
  @name_capitalized_plural = name_capitalize_pluralize
  @name_capitalized_single = name_capitalized_single
  @name_downcased_plural = name_downcased_pluralize
  @lower_name = lower_name
  @field_types = build_fields
  @field_names = fields.keys
  template('src/screens/base_index.dart.erb', "#{screen_path}/#{lower_name}_index_screen.dart")
  template('src/screens/base_bottom_navigation.dart.erb', "#{screen_path}/#{lower_name}_show_screen.dart")
  template('src/blocs/base_block.dart.erb', "#{src_directory}/blocs/#{name_downcased_pluralize}_bloc.dart")
  template('src/models/base_model.dart.erb', "#{src_directory}/models/#{name_downcased_pluralize}.dart")
  template('src/resources/base_api_provider.dart.erb', "#{src_directory}/resources/#{lower_name}_api_provider.dart")
  invoke :connect_widgets
end